aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-08-18 16:03:48 +0200
committerGitHub <noreply@github.com>2022-08-18 16:03:48 +0200
commit6664a251f1893e6ddc183aa6061d6f0fd4f40a57 (patch)
treee42bcfc39ccf9284f645dde7ae5990c6d4995ade /cache
parentec24de3f0d19ff1a56d0b12d389ec1535be43ea2 (diff)
parent45f5f852b71a63c142bca8b05efe53eebf142594 (diff)
downloadgit-bug-6664a251f1893e6ddc183aa6061d6f0fd4f40a57.tar.gz
Merge pull request #844 from MichaelMure/resolvers
WIP resolvers
Diffstat (limited to 'cache')
-rw-r--r--cache/repo_cache.go14
-rw-r--r--cache/repo_cache_bug.go2
-rw-r--r--cache/repo_cache_common.go2
-rw-r--r--cache/resolvers.go39
4 files changed, 23 insertions, 34 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index 53948331..8af221bb 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -49,6 +49,9 @@ type RepoCache struct {
// the name of the repository, as defined in the MultiRepoCache
name string
+ // resolvers for all known entities
+ resolvers entity.Resolvers
+
// maximum number of loaded bugs
maxLoadedBugs int
@@ -84,6 +87,8 @@ func NewNamedRepoCache(r repository.ClockedRepo, name string) (*RepoCache, error
identities: make(map[entity.Id]*IdentityCache),
}
+ c.resolvers = makeResolvers(c)
+
err := c.lock()
if err != nil {
return &RepoCache{}, err
@@ -168,13 +173,6 @@ func (c *RepoCache) Close() error {
}
func (c *RepoCache) buildCache() error {
- // TODO: make that parallel
-
- c.muBug.Lock()
- defer c.muBug.Unlock()
- c.muIdentity.Lock()
- defer c.muIdentity.Unlock()
-
_, _ = fmt.Fprintf(os.Stderr, "Building identity cache... ")
c.identitiesExcerpts = make(map[entity.Id]*IdentityExcerpt)
@@ -195,7 +193,7 @@ func (c *RepoCache) buildCache() error {
c.bugExcerpts = make(map[entity.Id]*BugExcerpt)
- allBugs := bug.ReadAllWithResolver(c.repo, newIdentityCacheResolverNoLock(c))
+ allBugs := bug.ReadAllWithResolver(c.repo, c.resolvers)
// wipe the index just to be sure
err := c.repo.ClearBleveIndex("bug")
diff --git a/cache/repo_cache_bug.go b/cache/repo_cache_bug.go
index 6af9fc04..a3f195ff 100644
--- a/cache/repo_cache_bug.go
+++ b/cache/repo_cache_bug.go
@@ -153,7 +153,7 @@ func (c *RepoCache) ResolveBug(id entity.Id) (*BugCache, error) {
}
c.muBug.RUnlock()
- b, err := bug.ReadWithResolver(c.repo, newIdentityCacheResolver(c), id)
+ b, err := bug.ReadWithResolver(c.repo, c.resolvers, id)
if err != nil {
return nil, err
}
diff --git a/cache/repo_cache_common.go b/cache/repo_cache_common.go
index 66797e80..49ec72d0 100644
--- a/cache/repo_cache_common.go
+++ b/cache/repo_cache_common.go
@@ -118,7 +118,7 @@ func (c *RepoCache) MergeAll(remote string) <-chan entity.MergeResult {
}
}
- results = bug.MergeAll(c.repo, remote, author)
+ results = bug.MergeAll(c.repo, c.resolvers, remote, author)
for result := range results {
out <- result
diff --git a/cache/resolvers.go b/cache/resolvers.go
index e53c3660..9ed2fa4c 100644
--- a/cache/resolvers.go
+++ b/cache/resolvers.go
@@ -2,10 +2,16 @@ package cache
import (
"github.com/MichaelMure/git-bug/entity"
- "github.com/MichaelMure/git-bug/identity"
)
-var _ identity.Resolver = &identityCacheResolver{}
+func makeResolvers(cache *RepoCache) entity.Resolvers {
+ return entity.Resolvers{
+ &IdentityCache{}: newIdentityCacheResolver(cache),
+ &BugCache{}: newBugCacheResolver(cache),
+ }
+}
+
+var _ entity.Resolver = &identityCacheResolver{}
// identityCacheResolver is an identity Resolver that retrieve identities from
// the cache
@@ -17,35 +23,20 @@ func newIdentityCacheResolver(cache *RepoCache) *identityCacheResolver {
return &identityCacheResolver{cache: cache}
}
-func (i *identityCacheResolver) ResolveIdentity(id entity.Id) (identity.Interface, error) {
+func (i *identityCacheResolver) Resolve(id entity.Id) (entity.Interface, error) {
return i.cache.ResolveIdentity(id)
}
-var _ identity.Resolver = &identityCacheResolverNoLock{}
+var _ entity.Resolver = &bugCacheResolver{}
-// identityCacheResolverNoLock is an identity Resolver that retrieve identities from
-// the cache, without locking it.
-type identityCacheResolverNoLock struct {
+type bugCacheResolver struct {
cache *RepoCache
}
-func newIdentityCacheResolverNoLock(cache *RepoCache) *identityCacheResolverNoLock {
- return &identityCacheResolverNoLock{cache: cache}
+func newBugCacheResolver(cache *RepoCache) *bugCacheResolver {
+ return &bugCacheResolver{cache: cache}
}
-func (ir *identityCacheResolverNoLock) ResolveIdentity(id entity.Id) (identity.Interface, error) {
- cached, ok := ir.cache.identities[id]
- if ok {
- return cached, nil
- }
-
- i, err := identity.ReadLocal(ir.cache.repo, id)
- if err != nil {
- return nil, err
- }
-
- cached = NewIdentityCache(ir.cache, i)
- ir.cache.identities[id] = cached
-
- return cached, nil
+func (b *bugCacheResolver) Resolve(id entity.Id) (entity.Interface, error) {
+ return b.cache.ResolveBug(id)
}