diff options
author | Michael Muré <batolettre@gmail.com> | 2022-08-13 12:08:48 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2022-08-18 15:55:48 +0200 |
commit | 45f5f852b71a63c142bca8b05efe53eebf142594 (patch) | |
tree | cb92d9f598b13dda69fbbc652a21d0ad8dc314c2 /cache/resolvers.go | |
parent | cd52872475f1b39f3fb6546606c1e78afb6c08e3 (diff) | |
download | git-bug-45f5f852b71a63c142bca8b05efe53eebf142594.tar.gz |
core: generalized resolvers to resolve any entity time when unmarshalling an operation
Diffstat (limited to 'cache/resolvers.go')
-rw-r--r-- | cache/resolvers.go | 39 |
1 files changed, 15 insertions, 24 deletions
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) } |