diff options
author | Michael Muré <batolettre@gmail.com> | 2022-12-23 01:48:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-23 01:48:14 +0100 |
commit | 0a5a0ec1ef4ad98bc2116a953e201f96474941ab (patch) | |
tree | 660a9b17b5247fe2f954bfa814cce3193c5afa23 /api | |
parent | 108518530e822e3bdf59c8bfc333ad0bbe2d5fc8 (diff) | |
parent | 95911100823b5c809225d664de74ad2d64e91972 (diff) | |
download | git-bug-0a5a0ec1ef4ad98bc2116a953e201f96474941ab.tar.gz |
Merge pull request #938 from MichaelMure/cache-reorg
Generic cache layer
Diffstat (limited to 'api')
-rw-r--r-- | api/auth/context.go | 2 | ||||
-rw-r--r-- | api/graphql/graphql_test.go | 5 | ||||
-rw-r--r-- | api/graphql/models/lazy_bug.go | 6 | ||||
-rw-r--r-- | api/graphql/models/lazy_identity.go | 6 | ||||
-rw-r--r-- | api/graphql/resolvers/mutation.go | 6 | ||||
-rw-r--r-- | api/graphql/resolvers/repo.go | 14 | ||||
-rw-r--r-- | api/http/git_file_handlers_test.go | 4 |
7 files changed, 23 insertions, 20 deletions
diff --git a/api/auth/context.go b/api/auth/context.go index 17171261..2547aaca 100644 --- a/api/auth/context.go +++ b/api/auth/context.go @@ -24,5 +24,5 @@ func UserFromCtx(ctx context.Context, r *cache.RepoCache) (*cache.IdentityCache, if !ok { return nil, ErrNotAuthenticated } - return r.ResolveIdentity(id) + return r.Identities().Resolve(id) } diff --git a/api/graphql/graphql_test.go b/api/graphql/graphql_test.go index 2ddfb314..a8dfad3f 100644 --- a/api/graphql/graphql_test.go +++ b/api/graphql/graphql_test.go @@ -19,8 +19,11 @@ func TestQueries(t *testing.T) { random_bugs.FillRepoWithSeed(repo, 10, 42) mrc := cache.NewMultiRepoCache() - _, err := mrc.RegisterDefaultRepository(repo) + _, events, err := mrc.RegisterDefaultRepository(repo) require.NoError(t, err) + for event := range events { + require.NoError(t, event.Err) + } handler := NewHandler(mrc, nil) diff --git a/api/graphql/models/lazy_bug.go b/api/graphql/models/lazy_bug.go index 318fdc99..4b0b598e 100644 --- a/api/graphql/models/lazy_bug.go +++ b/api/graphql/models/lazy_bug.go @@ -58,7 +58,7 @@ func (lb *lazyBug) load() error { return nil } - b, err := lb.cache.ResolveBug(lb.excerpt.Id) + b, err := lb.cache.Bugs().Resolve(lb.excerpt.Id()) if err != nil { return err } @@ -68,7 +68,7 @@ func (lb *lazyBug) load() error { } func (lb *lazyBug) identity(id entity.Id) (IdentityWrapper, error) { - i, err := lb.cache.ResolveIdentityExcerpt(id) + i, err := lb.cache.Identities().ResolveExcerpt(id) if err != nil { return nil, err } @@ -79,7 +79,7 @@ func (lb *lazyBug) identity(id entity.Id) (IdentityWrapper, error) { func (lb *lazyBug) IsAuthored() {} func (lb *lazyBug) Id() entity.Id { - return lb.excerpt.Id + return lb.excerpt.Id() } func (lb *lazyBug) LastEdit() time.Time { diff --git a/api/graphql/models/lazy_identity.go b/api/graphql/models/lazy_identity.go index 27bc9619..c19d077b 100644 --- a/api/graphql/models/lazy_identity.go +++ b/api/graphql/models/lazy_identity.go @@ -48,16 +48,16 @@ func (li *lazyIdentity) load() (*cache.IdentityCache, error) { return li.id, nil } - id, err := li.cache.ResolveIdentity(li.excerpt.Id) + id, err := li.cache.Identities().Resolve(li.excerpt.Id()) if err != nil { - return nil, fmt.Errorf("cache: missing identity %v", li.excerpt.Id) + return nil, fmt.Errorf("cache: missing identity %v", li.excerpt.Id()) } li.id = id return id, nil } func (li *lazyIdentity) Id() entity.Id { - return li.excerpt.Id + return li.excerpt.Id() } func (li *lazyIdentity) Name() string { diff --git a/api/graphql/resolvers/mutation.go b/api/graphql/resolvers/mutation.go index 3f9f7fe1..32e1fa7c 100644 --- a/api/graphql/resolvers/mutation.go +++ b/api/graphql/resolvers/mutation.go @@ -32,7 +32,7 @@ func (r mutationResolver) getBug(repoRef *string, bugPrefix string) (*cache.Repo return nil, nil, err } - b, err := repo.ResolveBugPrefix(bugPrefix) + b, err := repo.Bugs().ResolvePrefix(bugPrefix) if err != nil { return nil, nil, err } @@ -50,7 +50,7 @@ func (r mutationResolver) NewBug(ctx context.Context, input models.NewBugInput) return nil, err } - b, op, err := repo.NewBugRaw(author, + b, op, err := repo.Bugs().NewRaw(author, time.Now().Unix(), text.CleanupOneLine(input.Title), text.Cleanup(input.Message), @@ -181,7 +181,7 @@ func (r mutationResolver) EditComment(ctx context.Context, input models.EditComm return nil, err } - b, target, err := repo.ResolveComment(input.TargetPrefix) + b, target, err := repo.Bugs().ResolveComment(input.TargetPrefix) if err != nil { return nil, err } diff --git a/api/graphql/resolvers/repo.go b/api/graphql/resolvers/repo.go index 3fcaada1..67b03628 100644 --- a/api/graphql/resolvers/repo.go +++ b/api/graphql/resolvers/repo.go @@ -41,7 +41,7 @@ func (repoResolver) AllBugs(_ context.Context, obj *models.Repository, after *st } // Simply pass a []string with the ids to the pagination algorithm - source, err := obj.Repo.QueryBugs(q) + source, err := obj.Repo.Bugs().Query(q) if err != nil { return nil, err } @@ -60,7 +60,7 @@ func (repoResolver) AllBugs(_ context.Context, obj *models.Repository, after *st nodes := make([]models.BugWrapper, len(lazyBugEdges)) for i, lazyBugEdge := range lazyBugEdges { - excerpt, err := obj.Repo.ResolveBugExcerpt(lazyBugEdge.Id) + excerpt, err := obj.Repo.Bugs().ResolveExcerpt(lazyBugEdge.Id) if err != nil { return nil, err } @@ -86,7 +86,7 @@ func (repoResolver) AllBugs(_ context.Context, obj *models.Repository, after *st } func (repoResolver) Bug(_ context.Context, obj *models.Repository, prefix string) (models.BugWrapper, error) { - excerpt, err := obj.Repo.ResolveBugExcerptPrefix(prefix) + excerpt, err := obj.Repo.Bugs().ResolveExcerptPrefix(prefix) if err != nil { return nil, err } @@ -103,7 +103,7 @@ func (repoResolver) AllIdentities(_ context.Context, obj *models.Repository, aft } // Simply pass a []string with the ids to the pagination algorithm - source := obj.Repo.AllIdentityIds() + source := obj.Repo.Identities().AllIds() // The edger create a custom edge holding just the id edger := func(id entity.Id, offset int) connections.Edge { @@ -119,7 +119,7 @@ func (repoResolver) AllIdentities(_ context.Context, obj *models.Repository, aft nodes := make([]models.IdentityWrapper, len(lazyIdentityEdges)) for k, lazyIdentityEdge := range lazyIdentityEdges { - excerpt, err := obj.Repo.ResolveIdentityExcerpt(lazyIdentityEdge.Id) + excerpt, err := obj.Repo.Identities().ResolveExcerpt(lazyIdentityEdge.Id) if err != nil { return nil, err } @@ -145,7 +145,7 @@ func (repoResolver) AllIdentities(_ context.Context, obj *models.Repository, aft } func (repoResolver) Identity(_ context.Context, obj *models.Repository, prefix string) (models.IdentityWrapper, error) { - excerpt, err := obj.Repo.ResolveIdentityExcerptPrefix(prefix) + excerpt, err := obj.Repo.Identities().ResolveExcerptPrefix(prefix) if err != nil { return nil, err } @@ -187,5 +187,5 @@ func (repoResolver) ValidLabels(_ context.Context, obj *models.Repository, after }, nil } - return connections.LabelCon(obj.Repo.ValidLabels(), edger, conMaker, input) + return connections.LabelCon(obj.Repo.Bugs().ValidLabels(), edger, conMaker, input) } diff --git a/api/http/git_file_handlers_test.go b/api/http/git_file_handlers_test.go index 736bf75e..b2371abf 100644 --- a/api/http/git_file_handlers_test.go +++ b/api/http/git_file_handlers_test.go @@ -22,10 +22,10 @@ func TestGitFileHandlers(t *testing.T) { repo := repository.CreateGoGitTestRepo(t, false) mrc := cache.NewMultiRepoCache() - repoCache, err := mrc.RegisterDefaultRepository(repo) + repoCache, _, err := mrc.RegisterDefaultRepository(repo) require.NoError(t, err) - author, err := repoCache.NewIdentity("test identity", "test@test.org") + author, err := repoCache.Identities().New("test identity", "test@test.org") require.NoError(t, err) err = repoCache.SetUserIdentity(author) |