1package dag
2
3import (
4 "fmt"
5
6 "github.com/MichaelMure/git-bug/identity"
7 "github.com/MichaelMure/git-bug/repository"
8)
9
10// ClockLoader is the repository.ClockLoader for Entity
11func ClockLoader(defs ...Definition) repository.ClockLoader {
12 clocks := make([]string, len(defs)*2)
13 for _, def := range defs {
14 clocks = append(clocks, fmt.Sprintf(creationClockPattern, def.Namespace))
15 clocks = append(clocks, fmt.Sprintf(editClockPattern, def.Namespace))
16 }
17
18 return repository.ClockLoader{
19 Clocks: clocks,
20 Witnesser: func(repo repository.ClockedRepo) error {
21 // We don't care about the actual identity so an IdentityStub will do
22 resolver := identity.NewStubResolver()
23
24 for _, def := range defs {
25 // we actually just need to read all entities,
26 // as that will create and update the clocks
27 // TODO: concurrent loading to be faster?
28 for b := range ReadAll(def, repo, resolver) {
29 if b.Err != nil {
30 return b.Err
31 }
32 }
33 }
34 return nil
35 },
36 }
37}