diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-02 15:45:14 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-02 15:45:14 +0200 |
commit | 90a45b4c0979dd744aa5a28c84ececf243f027d2 (patch) | |
tree | bc2bea4bd1452b00685a7ad967027f78e626eba7 | |
parent | 6ff02ed84254275f2d19569a1a5f14efc1d47f31 (diff) | |
download | git-bug-90a45b4c0979dd744aa5a28c84ececf243f027d2.tar.gz git-bug-90a45b4c0979dd744aa5a28c84ececf243f027d2.zip |
cache: rename RootCache into MultiRepoCache
Underline the fact that it's fine to use RepoCache alone
-rw-r--r-- | cache/multi_repo_cache.go (renamed from cache/cache.go) | 16 | ||||
-rw-r--r-- | graphql/models/models.go | 4 | ||||
-rw-r--r-- | graphql/resolvers/mutation.go | 2 | ||||
-rw-r--r-- | graphql/resolvers/query.go | 2 | ||||
-rw-r--r-- | graphql/resolvers/root.go | 8 |
5 files changed, 16 insertions, 16 deletions
diff --git a/cache/cache.go b/cache/multi_repo_cache.go index 751467b2..ad43edab 100644 --- a/cache/cache.go +++ b/cache/multi_repo_cache.go @@ -9,18 +9,18 @@ import ( const lockfile = "lock" const excerptsFile = "excerpts" -type RootCache struct { +type MultiRepoCache struct { repos map[string]*RepoCache } -func NewCache() RootCache { - return RootCache{ +func NewMultiRepoCache() MultiRepoCache { + return MultiRepoCache{ repos: make(map[string]*RepoCache), } } // RegisterRepository register a named repository. Use this for multi-repo setup -func (c *RootCache) RegisterRepository(ref string, repo repository.Repo) error { +func (c *MultiRepoCache) RegisterRepository(ref string, repo repository.Repo) error { r, err := NewRepoCache(repo) if err != nil { return err @@ -31,7 +31,7 @@ func (c *RootCache) RegisterRepository(ref string, repo repository.Repo) error { } // RegisterDefaultRepository register a unnamed repository. Use this for mono-repo setup -func (c *RootCache) RegisterDefaultRepository(repo repository.Repo) error { +func (c *MultiRepoCache) RegisterDefaultRepository(repo repository.Repo) error { r, err := NewRepoCache(repo) if err != nil { return err @@ -42,7 +42,7 @@ func (c *RootCache) RegisterDefaultRepository(repo repository.Repo) error { } // ResolveRepo retrieve a repository by name -func (c *RootCache) DefaultRepo() (*RepoCache, error) { +func (c *MultiRepoCache) DefaultRepo() (*RepoCache, error) { if len(c.repos) != 1 { return nil, fmt.Errorf("repository is not unique") } @@ -55,7 +55,7 @@ func (c *RootCache) DefaultRepo() (*RepoCache, error) { } // DefaultRepo retrieve the default repository -func (c *RootCache) ResolveRepo(ref string) (*RepoCache, error) { +func (c *MultiRepoCache) ResolveRepo(ref string) (*RepoCache, error) { r, ok := c.repos[ref] if !ok { return nil, fmt.Errorf("unknown repo") @@ -64,7 +64,7 @@ func (c *RootCache) ResolveRepo(ref string) (*RepoCache, error) { } // Close will do anything that is needed to close the cache properly -func (c *RootCache) Close() error { +func (c *MultiRepoCache) Close() error { for _, cachedRepo := range c.repos { err := cachedRepo.Close() if err != nil { diff --git a/graphql/models/models.go b/graphql/models/models.go index dfe3a29f..63d9c1fe 100644 --- a/graphql/models/models.go +++ b/graphql/models/models.go @@ -12,11 +12,11 @@ type ConnectionInput struct { } type Repository struct { - Cache *cache.RootCache + Cache *cache.MultiRepoCache Repo *cache.RepoCache } type RepositoryMutation struct { - Cache *cache.RootCache + Cache *cache.MultiRepoCache Repo *cache.RepoCache } diff --git a/graphql/resolvers/mutation.go b/graphql/resolvers/mutation.go index 674c1775..7cc98aac 100644 --- a/graphql/resolvers/mutation.go +++ b/graphql/resolvers/mutation.go @@ -9,7 +9,7 @@ import ( ) type mutationResolver struct { - cache *cache.RootCache + cache *cache.MultiRepoCache } func (r mutationResolver) getRepo(repoRef *string) (*cache.RepoCache, error) { diff --git a/graphql/resolvers/query.go b/graphql/resolvers/query.go index 0e7f3a6f..b5763b72 100644 --- a/graphql/resolvers/query.go +++ b/graphql/resolvers/query.go @@ -8,7 +8,7 @@ import ( ) type rootQueryResolver struct { - cache *cache.RootCache + cache *cache.MultiRepoCache } func (r rootQueryResolver) DefaultRepository(ctx context.Context) (*models.Repository, error) { diff --git a/graphql/resolvers/root.go b/graphql/resolvers/root.go index 767e82d2..1003f7f1 100644 --- a/graphql/resolvers/root.go +++ b/graphql/resolvers/root.go @@ -6,24 +6,24 @@ import ( ) type RootResolver struct { - cache.RootCache + cache.MultiRepoCache } func NewRootResolver() *RootResolver { return &RootResolver{ - RootCache: cache.NewCache(), + MultiRepoCache: cache.NewMultiRepoCache(), } } func (r RootResolver) Query() graph.QueryResolver { return &rootQueryResolver{ - cache: &r.RootCache, + cache: &r.MultiRepoCache, } } func (r RootResolver) Mutation() graph.MutationResolver { return &mutationResolver{ - cache: &r.RootCache, + cache: &r.MultiRepoCache, } } |