aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag/clock.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-02-11 09:52:09 +0100
committerMichael Muré <batolettre@gmail.com>2021-02-14 12:19:04 +0100
commit71e22d9f6e49ce0c3bc3b177323b17652a1c45a2 (patch)
tree5c72bb2ce9b8602530e5b1ed6d977f95f15e50fc /entity/dag/clock.go
parent59e9981161acea461a3ef9d386f20e23e78d8433 (diff)
downloadgit-bug-71e22d9f6e49ce0c3bc3b177323b17652a1c45a2.tar.gz
entity: clock loader
Diffstat (limited to 'entity/dag/clock.go')
-rw-r--r--entity/dag/clock.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/entity/dag/clock.go b/entity/dag/clock.go
new file mode 100644
index 00000000..fa944b33
--- /dev/null
+++ b/entity/dag/clock.go
@@ -0,0 +1,41 @@
+package dag
+
+import (
+ "fmt"
+
+ "github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/repository"
+)
+
+// ClockLoader is the repository.ClockLoader for Entity
+func ClockLoader(defs ...Definition) repository.ClockLoader {
+ clocks := make([]string, 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 {
+ // We don't care about the actual identity so an IdentityStub will do
+ resolver := identity.NewStubResolver()
+
+ for _, def := range defs {
+ // override the resolver
+ def := def
+ def.identityResolver = resolver
+
+ // we actually just need to read all entities,
+ // as that will create and update the clocks
+ // TODO: concurrent loading to be faster?
+ for b := range ReadAll(def, repo) {
+ if b.Err != nil {
+ return b.Err
+ }
+ }
+ }
+ return nil
+ },
+ }
+}