diff options
author | Michael Muré <batolettre@gmail.com> | 2022-11-15 19:27:01 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2022-11-15 19:27:01 +0100 |
commit | d1744f5ee2c55176bb877f7d13b92efd29877077 (patch) | |
tree | c2d53c9efd651e9de81eaa9be36771345f557489 /repository/gogit.go | |
parent | 53059ecbfefe21e5e87d06ca44e3cd99a66c0c5f (diff) | |
download | git-bug-d1744f5ee2c55176bb877f7d13b92efd29877077.tar.gz |
go-git: concurrent loading of clocks
Diffstat (limited to 'repository/gogit.go')
-rw-r--r-- | repository/gogit.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/repository/gogit.go b/repository/gogit.go index 4e3ccfb8..7dd5a48d 100644 --- a/repository/gogit.go +++ b/repository/gogit.go @@ -20,6 +20,7 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/filemode" "github.com/go-git/go-git/v5/plumbing/object" + "golang.org/x/sync/errgroup" "golang.org/x/sys/execabs" "github.com/MichaelMure/git-bug/util/lamport" @@ -79,7 +80,9 @@ func OpenGoGitRepo(path, namespace string, clockLoaders []ClockLoader) (*GoGitRe localStorage: osfs.New(filepath.Join(path, namespace)), } + loaderToRun := make([]ClockLoader, len(clockLoaders)) for _, loader := range clockLoaders { + loader := loader allExist := true for _, name := range loader.Clocks { if _, err := repo.getClock(name); err != nil { @@ -88,13 +91,22 @@ func OpenGoGitRepo(path, namespace string, clockLoaders []ClockLoader) (*GoGitRe } if !allExist { - err = loader.Witnesser(repo) - if err != nil { - return nil, err - } + loaderToRun = append(loaderToRun, loader) } } + var errG errgroup.Group + for _, loader := range loaderToRun { + loader := loader + errG.Go(func() error { + return loader.Witnesser(repo) + }) + } + err = errG.Wait() + if err != nil { + return nil, err + } + return repo, nil } |