aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag/clock.go
blob: f773e15c4ef831cde04d9ced66285a831cb39de5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package dag

import (
	"fmt"

	"golang.org/x/sync/errgroup"

	"github.com/git-bug/git-bug/repository"
)

// ClockLoader is the repository.ClockLoader for Entity
func ClockLoader(defs ...Definition) repository.ClockLoader {
	clocks := make([]string, 0, len(defs)*2)
	for _, def := range defs {
		clocks = append(clocks, fmt.Sprintf(creationClockPattern, def.Namespace))
		clocks = append(clocks, fmt.Sprintf(editClockPattern, def.Namespace))
	}

	return repository.ClockLoader{
		Clocks: clocks,
		Witnesser: func(repo repository.ClockedRepo) error {
			var errG errgroup.Group
			for _, def := range defs {
				def := def
				errG.Go(func() error {
					return ReadAllClocksNoCheck(def, repo)
				})
			}
			return errG.Wait()
		},
	}
}