Skip to content

Commit dd027b4

Browse files
committed
chore: more speedup
Signed-off-by: Valery Piashchynski <[email protected]>
1 parent 34d02e9 commit dd027b4

File tree

10 files changed

+54
-39
lines changed

10 files changed

+54
-39
lines changed

builder/builder.go

+12-19
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo
6363
t.Entries = make([]*templates.Entry, len(b.modules))
6464
for i := 0; i < len(b.modules); i++ {
6565
t.Entries[i] = &templates.Entry{
66+
Time: b.modules[i].Time,
6667
Module: b.modules[i].ModuleName,
6768
Prefix: randStringBytes(5),
6869
Structure: pluginStructureStr,
@@ -73,7 +74,7 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo
7374

7475
buf := new(bytes.Buffer)
7576

76-
// compatibility with the version 2
77+
// compatibility with version 2
7778
switch t.ModuleVersion {
7879
case velox.V2023:
7980
err = templates.CompileTemplateV2023(buf, t)
@@ -131,7 +132,7 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo
131132

132133
buf.Reset()
133134

134-
// compatibility with the version 2
135+
// compatibility with version 2
135136
switch t.ModuleVersion {
136137
case velox.V2023:
137138
err = templates.CompileGoModTemplate2023(buf, t)
@@ -160,16 +161,9 @@ func (b *Builder) Build(rrModule string) error { //nolint:gocyclo
160161
return err
161162
}
162163

163-
for i := 0; i < len(t.Entries); i++ {
164-
// go get only deps w/o replace
165-
if t.Entries[i].Replace != "" {
166-
t.Entries = append(t.Entries, b.getDepsReplace(t.Entries[i].Replace)...)
167-
continue
168-
}
169-
err = b.goGetMod(t.Entries[i].Module, t.Entries[i].Version)
170-
if err != nil {
171-
return err
172-
}
164+
err = b.goModDowloadCmd()
165+
if err != nil {
166+
return err
173167
}
174168

175169
err = b.goModTidyCmd()
@@ -259,9 +253,9 @@ func (b *Builder) goBuildCmd(out string) error {
259253
return nil
260254
}
261255

262-
func (b *Builder) goModTidyCmd() error {
263-
b.log.Info("[EXECUTING CMD]", zap.String("cmd", "go mod tidy"))
264-
cmd := exec.Command("go", "mod", "tidy")
256+
func (b *Builder) goModDowloadCmd() error {
257+
b.log.Info("[EXECUTING CMD]", zap.String("cmd", "go mod download"))
258+
cmd := exec.Command("go", "mod", "download")
265259
cmd.Stderr = b
266260
err := cmd.Start()
267261
if err != nil {
@@ -274,11 +268,10 @@ func (b *Builder) goModTidyCmd() error {
274268
return nil
275269
}
276270

277-
func (b *Builder) goGetMod(repo, hash string) error {
278-
b.log.Info("[EXECUTING CMD]", zap.String("cmd", "go get "+repo+"@"+hash))
279-
cmd := exec.Command("go", "get", repo+"@"+hash) //nolint:gosec
271+
func (b *Builder) goModTidyCmd() error {
272+
b.log.Info("[EXECUTING CMD]", zap.String("cmd", "go mod tidy"))
273+
cmd := exec.Command("go", "mod", "tidy")
280274
cmd.Stderr = b
281-
282275
err := cmd.Start()
283276
if err != nil {
284277
return err

builder/templates/entry.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77

88
// Entry represents all info about module
99
type Entry struct {
10+
Time string
1011
Module string
1112
Structure string
1213
Prefix string
1314
Version string
14-
// Replace directive, should include path
15+
// Replace directive, should include a path
1516
Replace string
1617
}
1718

builder/templates/templateV2023.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module github.com/roadrunner-server/roadrunner/{{.ModuleVersion}}
55
66
go 1.21
77
8-
toolchain go1.21.0
8+
toolchain go1.21.1
99
1010
require (
1111
github.com/buger/goterm v1.0.4
@@ -16,6 +16,10 @@ require (
1616
github.com/spf13/viper v1.15.0
1717
github.com/stretchr/testify v1.8.2
1818
go.uber.org/automaxprocs v1.5.2
19+
20+
// Go module pseudo-version
21+
{{range $v := .Entries}}{{$v.Module}} v4.0.0-{{$v.Time}}-{{$v.Version}}
22+
{{end}}
1923
)
2024
2125
replace (

cmd/vx/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func main() {
12-
// os.Args[0] always contains path to the executable, like foo/bar/rr -> rr
12+
// os.Args[0] always contains a path to the executable, like foo/bar/rr -> rr
1313
cmd := cli.NewCommand(filepath.Base(os.Args[0]))
1414
err := cmd.Execute()
1515
if err != nil {

github/pool.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import (
1010
"sync"
1111
"time"
1212

13-
"github.com/google/go-github/v49/github"
13+
"github.com/google/go-github/v53/github"
1414
"github.com/roadrunner-server/velox"
1515
"go.uber.org/zap"
1616
)
1717

18+
const (
19+
referenceFormat string = "20060102150405"
20+
)
21+
1822
type processor struct {
1923
maxWorkers int
2024
errs []error
@@ -150,7 +154,10 @@ func (p *processor) run() {
150154
}
151155

152156
for j := 0; j < len(commits); j++ {
153-
modInfo.Version = *commits[j].SHA
157+
at := commits[j].GetCommit().GetCommitter().GetDate()
158+
modInfo.Time = at.Format(referenceFormat)
159+
// [:12] because of go.mod pseudo format specs
160+
modInfo.Version = commits[j].GetSHA()[:12]
154161
}
155162

156163
if v.pluginCfg.Replace != "" {

github/repo.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"path/filepath"
1414
"strings"
1515

16-
"github.com/google/go-github/v49/github"
16+
"github.com/google/go-github/v53/github"
1717
"github.com/roadrunner-server/velox"
1818
"go.uber.org/zap"
1919
"golang.org/x/oauth2"
@@ -28,7 +28,6 @@ const (
2828
GHRepo represents template repository
2929
*/
3030
type GHRepo struct {
31-
pool *processor
3231
client *github.Client
3332
config *velox.Config
3433
log *zap.Logger
@@ -37,15 +36,14 @@ type GHRepo struct {
3736
func NewGHRepoInfo(cfg *velox.Config, log *zap.Logger) *GHRepo {
3837
var client *http.Client
3938

40-
// if token exists, use it to increase rate limiter
39+
// if a token exists, use it to increase rate limiter
4140
if t := cfg.GitHub.Token; t != nil {
4241
ctx := context.Background()
4342
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: t.Token})
4443
client = oauth2.NewClient(ctx, ts)
4544
}
4645

4746
return &GHRepo{
48-
pool: newPool(log, github.NewClient(client)),
4947
log: log,
5048
config: cfg,
5149
client: github.NewClient(client),
@@ -198,21 +196,22 @@ func extract(dest string, zf *zip.File) error {
198196
// https://github.com/spiral/roadrunner-binary/archive/refs/tags/v2.7.0.zip
199197

200198
func (r *GHRepo) GetPluginsModData() ([]*velox.ModulesInfo, error) {
199+
poolExecutor := newPool(r.log, r.client)
201200
for k, v := range r.config.GitHub.Plugins {
202-
r.pool.add(&pcfg{
201+
poolExecutor.add(&pcfg{
203202
pluginCfg: v,
204203
name: k,
205204
})
206205
}
207206

208-
r.pool.wait()
207+
poolExecutor.wait()
209208

210-
if len(r.pool.errors()) != 0 {
211-
return nil, errors.Join(r.pool.errors()...)
209+
if len(poolExecutor.errors()) != 0 {
210+
return nil, errors.Join(poolExecutor.errors()...)
212211
}
213212

214-
mi := r.pool.moduleinfo()
215-
r.pool.stop()
213+
mi := poolExecutor.moduleinfo()
214+
poolExecutor.stop()
216215

217216
return mi, nil
218217
}

go.mod

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module github.com/roadrunner-server/velox
22

33
go 1.21
44

5-
toolchain go1.21.0
5+
toolchain go1.21.1
66

77
require (
88
github.com/fatih/color v1.15.0
9-
github.com/google/go-github/v49 v49.1.0
9+
github.com/google/go-github/v53 v53.2.0
1010
github.com/hashicorp/go-version v1.6.0
1111
github.com/pkg/errors v0.9.1
1212
github.com/spf13/cobra v1.7.0
@@ -18,6 +18,8 @@ require (
1818
)
1919

2020
require (
21+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
22+
github.com/cloudflare/circl v1.3.3 // indirect
2123
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2224
github.com/fsnotify/fsnotify v1.6.0 // indirect
2325
github.com/golang/protobuf v1.5.3 // indirect

go.sum

+9-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
3838
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3939
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4040
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
41+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
42+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
43+
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
4144
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4245
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
4346
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
4447
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
4548
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
49+
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
50+
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
51+
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
4652
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
4753
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
4854
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
@@ -109,8 +115,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
109115
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
110116
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
111117
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
112-
github.com/google/go-github/v49 v49.1.0 h1:LFkMgawGQ8dfzWLH/rNE0b3u1D3n6/dw7ZmrN3b+YFY=
113-
github.com/google/go-github/v49 v49.1.0/go.mod h1:MUUzHPrhGniB6vUKa27y37likpipzG+BXXJbG04J334=
118+
github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI=
119+
github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao=
114120
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
115121
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
116122
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
@@ -365,6 +371,7 @@ golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7w
365371
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
366372
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
367373
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
374+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
368375
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
369376
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
370377
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

modulesInfo.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package velox
22

33
// ModulesInfo represents single go module
44
type ModulesInfo struct {
5+
// Time - commit time
6+
Time string
57
// Version - commit sha or tag
68
Version string
79
// module name - eg: github.com/roadrunner-server/logger/v2

velox_rr_v2023.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ ref = "v2023.3.0"
8686
# test_plugin_2 = { ref = "main", owner = "rustatian", repository = "36405235" }
8787
#
8888
[log]
89-
level = "error"
89+
level = "debug"
9090
mode = "development"

0 commit comments

Comments
 (0)