Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/gitness/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions registry/app/api/controller/mocks/registry_finder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions registry/app/services/refcache/reg_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ import (
"github.com/harness/gitness/app/store/cache"
"github.com/harness/gitness/registry/app/store"
"github.com/harness/gitness/registry/types"

"github.com/google/uuid"
)

type RegistryFinder interface {
MarkChanged(ctx context.Context, reg *types.Registry)
FindByID(ctx context.Context, repoID int64) (*types.Registry, error)
FindByUUID(ctx context.Context, repoUUID uuid.UUID) (*types.Registry, error)
FindByRootRef(ctx context.Context, rootParentRef string, regIdentifier string) (
*types.Registry,
error,
Expand All @@ -42,6 +45,7 @@ type RegistryFinder interface {
type registryFinder struct {
inner store.RegistryRepository
regIDCache store.RegistryIDCache
regUUIDCache store.RegistryUUIDCache
regRootRefCache store.RegistryRootRefCache
spaceFinder refcache.SpaceFinder
evictor cache.Evictor[*types.Registry]
Expand All @@ -51,6 +55,7 @@ type registryFinder struct {
func NewRegistryFinder(
registryRepository store.RegistryRepository,
regIDCache store.RegistryIDCache,
regUUIDCache store.RegistryUUIDCache,
regRootRefCache store.RegistryRootRefCache,
evictor cache.Evictor[*types.Registry],
spaceFinder refcache.SpaceFinder,
Expand All @@ -59,6 +64,7 @@ func NewRegistryFinder(
return registryFinder{
inner: registryRepository,
regIDCache: regIDCache,
regUUIDCache: regUUIDCache,
regRootRefCache: regRootRefCache,
evictor: evictor,
spaceFinder: spaceFinder,
Expand All @@ -82,6 +88,10 @@ func (r registryFinder) FindByID(ctx context.Context, repoID int64) (*types.Regi
return r.regIDCache.Get(ctx, repoID)
}

func (r registryFinder) FindByUUID(ctx context.Context, repoUUID uuid.UUID) (*types.Registry, error) {
return r.regUUIDCache.Get(ctx, repoUUID.String())
}

func (r registryFinder) FindByRootRef(ctx context.Context, rootParentRef string, regIdentifier string) (
*types.Registry,
error,
Expand Down
11 changes: 10 additions & 1 deletion registry/app/services/refcache/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ import (
func ProvideRegistryFinder(
registryRepository store.RegistryRepository,
regIDCache store.RegistryIDCache,
regUUIDCache store.RegistryUUIDCache,
regRootRefCache store.RegistryRootRefCache,
evictor cache.Evictor[*types.Registry],
spaceFinder refcache.SpaceFinder,
upstreamProxyFinder UpstreamProxyFinder,
) RegistryFinder {
return NewRegistryFinder(registryRepository, regIDCache, regRootRefCache, evictor, spaceFinder, upstreamProxyFinder)
return NewRegistryFinder(
registryRepository,
regIDCache,
regUUIDCache,
regRootRefCache,
evictor,
spaceFinder,
upstreamProxyFinder,
)
}

func ProvideUpstreamProxyFinder(
Expand Down
1 change: 1 addition & 0 deletions registry/app/store/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ import (
type (
RegistryIDCache cache.Cache[int64, *types.Registry]
RegistryRootRefCache cache.Cache[types.RegistryRootRefCacheKey, int64]
RegistryUUIDCache cache.Cache[string, *types.Registry]
UpstreamProxyRegistryIDCache cache.Cache[int64, *types.UpstreamProxy]
)
55 changes: 55 additions & 0 deletions registry/app/store/cache/reg_uuid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cache

import (
"context"
"fmt"
"time"

cache2 "github.com/harness/gitness/app/store/cache"
"github.com/harness/gitness/cache"
"github.com/harness/gitness/registry/app/store"
"github.com/harness/gitness/registry/types"
)

func NewRegistryUUIDCache(
appCtx context.Context,
regSource store.RegistryRepository,
evictorRepo cache2.Evictor[*types.Registry],
dur time.Duration,
) store.RegistryUUIDCache {
c := cache.New[string, *types.Registry](registryUUIDCacheGetter{regSource: regSource}, dur)

evictorRepo.Subscribe(appCtx, func(repoCore *types.Registry) error {
c.Evict(appCtx, repoCore.UUID)
return nil
})

return c
}

type registryUUIDCacheGetter struct {
regSource store.RegistryRepository
}

func (c registryUUIDCacheGetter) Find(ctx context.Context, repoUUID string) (*types.Registry, error) {
repo, err := c.regSource.GetByUUID(ctx, repoUUID)
if err != nil {
return nil, fmt.Errorf("failed to find repo by UUID: %w", err)
}

return repo, nil
Comment on lines +48 to +54

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

rg -n "GetByUUID" --type=go -C3

Repository: abhinavcode/harness

Length of output: 13761


Use "registry" instead of "repo" in the error message for domain consistency

The error message on line 51 uses "repo" but the method returns *types.Registry. Change "failed to find repo by UUID" to "failed to find registry by UUID" to align with the domain terminology.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@registry/app/store/cache/reg_uuid.go` around lines 48 - 54, The error message
in registryUUIDCacheGetter.Find uses "repo" but the method deals with
types.Registry; update the fmt.Errorf call in registryUUIDCacheGetter.Find (the
error returned from regSource.GetByUUID) to use "failed to find registry by
UUID" instead of "failed to find repo by UUID" so domain terminology matches
types.Registry and regSource.GetByUUID.

}
9 changes: 9 additions & 0 deletions registry/app/store/cache/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ func ProvideRegRootRefCache(
return NewRegistryRootRefCache(appCtx, regSource, evictorRepo, registryCacheDuration)
}

func ProvideRegistryUUIDCache(
appCtx context.Context,
regSource store.RegistryRepository,
evictorRepo cache.Evictor[*types.Registry],
) store.RegistryUUIDCache {
return NewRegistryUUIDCache(appCtx, regSource, evictorRepo, registryCacheDuration)
}

func ProvideUpstreamProxyRegistryIDCache(
appCtx context.Context,
upstreamProxySource store.UpstreamProxyConfigRepository,
Expand All @@ -74,5 +82,6 @@ var WireSet = wire.NewSet(
ProvideEvictorUpstreamProxy,
ProvideRegRootRefCache,
ProvideRegistryIDCache,
ProvideRegistryUUIDCache,
ProvideUpstreamProxyRegistryIDCache,
)