aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
Diffstat (limited to 'cache')
-rw-r--r--cache/bug_cache.go2
-rw-r--r--cache/bug_excerpt.go7
-rw-r--r--cache/filter.go4
-rw-r--r--cache/identity_cache.go2
-rw-r--r--cache/identity_excerpt.go2
-rw-r--r--cache/repo_cache.go18
-rw-r--r--cache/repo_cache_bug.go4
-rw-r--r--cache/repo_cache_common.go6
-rw-r--r--cache/repo_cache_identity.go2
-rw-r--r--cache/repo_cache_test.go2
-rw-r--r--cache/resolvers.go39
11 files changed, 39 insertions, 49 deletions
diff --git a/cache/bug_cache.go b/cache/bug_cache.go
index 7503fc37..e03b27ff 100644
--- a/cache/bug_cache.go
+++ b/cache/bug_cache.go
@@ -5,7 +5,7 @@ import (
"sync"
"time"
- "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/entity/dag"
"github.com/MichaelMure/git-bug/repository"
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go
index 342a0553..7e3bcad4 100644
--- a/cache/bug_excerpt.go
+++ b/cache/bug_excerpt.go
@@ -5,9 +5,10 @@ import (
"fmt"
"time"
- "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/entities/bug"
+ "github.com/MichaelMure/git-bug/entities/common"
+ "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
- "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/lamport"
)
@@ -27,7 +28,7 @@ type BugExcerpt struct {
EditUnixTime int64
AuthorId entity.Id
- Status bug.Status
+ Status common.Status
Labels []bug.Label
Title string
LenComments int
diff --git a/cache/filter.go b/cache/filter.go
index 7ea40673..299e7c83 100644
--- a/cache/filter.go
+++ b/cache/filter.go
@@ -3,7 +3,7 @@ package cache
import (
"strings"
- "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/entities/common"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/query"
)
@@ -18,7 +18,7 @@ type resolver interface {
type Filter func(excerpt *BugExcerpt, resolver resolver) bool
// StatusFilter return a Filter that match a bug status
-func StatusFilter(status bug.Status) Filter {
+func StatusFilter(status common.Status) Filter {
return func(excerpt *BugExcerpt, resolver resolver) bool {
return excerpt.Status == status
}
diff --git a/cache/identity_cache.go b/cache/identity_cache.go
index e419387f..3b7bb818 100644
--- a/cache/identity_cache.go
+++ b/cache/identity_cache.go
@@ -1,7 +1,7 @@
package cache
import (
- "github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/repository"
)
diff --git a/cache/identity_excerpt.go b/cache/identity_excerpt.go
index 18514e9a..0166f493 100644
--- a/cache/identity_excerpt.go
+++ b/cache/identity_excerpt.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
+ "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
- "github.com/MichaelMure/git-bug/identity"
)
// Package initialisation used to register the type for (de)serialization
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index 53948331..71abf968 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -8,9 +8,9 @@ import (
"strconv"
"sync"
- "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/entities/bug"
+ "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
- "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util/process"
)
@@ -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..9843f9d9 100644
--- a/cache/repo_cache_bug.go
+++ b/cache/repo_cache_bug.go
@@ -12,7 +12,7 @@ import (
"github.com/blevesearch/bleve"
- "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/query"
"github.com/MichaelMure/git-bug/repository"
@@ -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..43ac6beb 100644
--- a/cache/repo_cache_common.go
+++ b/cache/repo_cache_common.go
@@ -6,9 +6,9 @@ import (
"github.com/go-git/go-billy/v5"
"github.com/pkg/errors"
- "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/entities/bug"
+ "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
- "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/repository"
)
@@ -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/repo_cache_identity.go b/cache/repo_cache_identity.go
index 75453cb8..eb30687c 100644
--- a/cache/repo_cache_identity.go
+++ b/cache/repo_cache_identity.go
@@ -5,8 +5,8 @@ import (
"encoding/gob"
"fmt"
+ "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
- "github.com/MichaelMure/git-bug/identity"
)
const identityCacheFile = "identity-cache"
diff --git a/cache/repo_cache_test.go b/cache/repo_cache_test.go
index c01f5478..a9557ff0 100644
--- a/cache/repo_cache_test.go
+++ b/cache/repo_cache_test.go
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/query"
"github.com/MichaelMure/git-bug/repository"
)
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)
}