aboutsummaryrefslogtreecommitdiffstats
path: root/cache/identity_subcache.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-12-19 18:09:59 +0100
committerMichael Muré <batolettre@gmail.com>2022-12-19 18:09:59 +0100
commitf2def3a9331080a02e57710a859d2aac608ed44c (patch)
tree2697224efb96110b65489877b5ba7d67d508eb5e /cache/identity_subcache.go
parent60d40d60e9f91247b61f541888f1469bff44f573 (diff)
downloadgit-bug-f2def3a9331080a02e57710a859d2aac608ed44c.tar.gz
WIP
Diffstat (limited to 'cache/identity_subcache.go')
-rw-r--r--cache/identity_subcache.go33
1 files changed, 31 insertions, 2 deletions
diff --git a/cache/identity_subcache.go b/cache/identity_subcache.go
index a3b5a0f8..b175d731 100644
--- a/cache/identity_subcache.go
+++ b/cache/identity_subcache.go
@@ -4,10 +4,39 @@ import (
"fmt"
"github.com/MichaelMure/git-bug/entities/identity"
+ "github.com/MichaelMure/git-bug/entity"
+ "github.com/MichaelMure/git-bug/repository"
)
type RepoCacheIdentity struct {
- SubCache[*IdentityExcerpt, *IdentityCache, identity.Interface]
+ *SubCache[*identity.Identity, *IdentityExcerpt, *IdentityCache]
+}
+
+func NewRepoCacheIdentity(repo repository.ClockedRepo,
+ resolvers func() entity.Resolvers,
+ getUserIdentity getUserIdentityFunc) *RepoCacheIdentity {
+
+ makeCached := func(i *identity.Identity, entityUpdated func(id entity.Id) error) *IdentityCache {
+ return NewIdentityCache(i, repo, entityUpdated)
+ }
+
+ makeExcerpt := func(i *identity.Identity) *IdentityExcerpt {
+ return NewIdentityExcerpt(i)
+ }
+
+ makeIndex := func(i *IdentityCache) []string {
+ // no indexing
+ return nil
+ }
+
+ sc := NewSubCache[*identity.Identity, *IdentityExcerpt, *IdentityCache](
+ repo, resolvers, getUserIdentity,
+ makeCached, makeExcerpt, makeIndex,
+ "identity", "identities",
+ formatVersion, defaultMaxLoadedBugs,
+ )
+
+ return &RepoCacheIdentity{SubCache: sc}
}
// ResolveIdentityImmutableMetadata retrieve an Identity that has the exact given metadata on
@@ -65,7 +94,7 @@ func (c *RepoCacheIdentity) finishIdentity(i *identity.Identity, metadata map[st
return nil, fmt.Errorf("identity %s already exist in the cache", i.Id())
}
- cached := NewIdentityCache(c, i)
+ cached := NewIdentityCache(i, c.repo, c.entityUpdated)
c.cached[i.Id()] = cached
c.mu.Unlock()