Skip to content

Commit

Permalink
Revise caching strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbelamaric committed Dec 19, 2023
1 parent 8771225 commit 89b289f
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 233 deletions.
4 changes: 2 additions & 2 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (c *Cache) OpenRepository(ctx context.Context, repositorySpec *configapi.Re
if !isPackageContent(repositorySpec.Spec.Content) {
return nil, fmt.Errorf("git repository supports Package content only; got %q", string(repositorySpec.Spec.Content))
}
key := "git://" + gitSpec.Repo
key := "git://" + gitSpec.Repo + gitSpec.Directory

c.mutex.Lock()
defer c.mutex.Unlock()
Expand Down Expand Up @@ -175,7 +175,7 @@ func (c *Cache) CloseRepository(repositorySpec *configapi.Repository) error {
if git == nil {
return fmt.Errorf("git not configured for %s:%s", repositorySpec.ObjectMeta.Namespace, repositorySpec.ObjectMeta.Name)
}
key = "git://" + git.Repo
key = "git://" + git.Repo + git.Directory

default:
return fmt.Errorf("unknown repository type: %q", repositorySpec.Spec.Type)
Expand Down
18 changes: 15 additions & 3 deletions pkg/cache/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cache

import (
"context"
"fmt"

"github.com/nephio-project/porch/pkg/repository"
)
Expand All @@ -28,9 +29,20 @@ type cachedDraft struct {
var _ repository.PackageDraft = &cachedDraft{}

func (cd *cachedDraft) Close(ctx context.Context) (repository.PackageRevision, error) {
if closed, err := cd.PackageDraft.Close(ctx); err != nil {
closed, err := cd.PackageDraft.Close(ctx)
if err != nil {
return nil, err
} else {
return cd.cache.update(ctx, closed)
}

err = cd.cache.reconcileCache(ctx, "close-draft")
if err != nil {
return nil, err
}

cpr := cd.cache.getPackageRevision(closed.Key())
if cpr == nil {
return nil, fmt.Errorf("closed draft not found")
}

return cpr, nil
}
Loading

0 comments on commit 89b289f

Please sign in to comment.