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 | |
parent | 53059ecbfefe21e5e87d06ca44e3cd99a66c0c5f (diff) | |
download | git-bug-d1744f5ee2c55176bb877f7d13b92efd29877077.tar.gz |
go-git: concurrent loading of clocks
-rw-r--r-- | entity/dag/clock.go | 1 | ||||
-rw-r--r-- | repository/gogit.go | 20 |
2 files changed, 17 insertions, 4 deletions
diff --git a/entity/dag/clock.go b/entity/dag/clock.go index 74a6cd73..a195df1f 100644 --- a/entity/dag/clock.go +++ b/entity/dag/clock.go @@ -21,6 +21,7 @@ func ClockLoader(defs ...Definition) repository.ClockLoader { Witnesser: func(repo repository.ClockedRepo) error { var errG errgroup.Group for _, def := range defs { + def := def errG.Go(func() error { return ReadAllClocksNoCheck(def, repo) }) 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 } |