Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vulncheck's repo cache to be concurrency-friendly #1351

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions internal/engine/eval/vulncheck/pkgdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"net/url"
"strings"

"github.com/puzpuzpuz/xsync"

Check failure on line 28 in internal/engine/eval/vulncheck/pkgdb.go

View workflow job for this annotation

GitHub Actions / golangci-lint / Go Lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/stacklok/mediator) (gci)
"github.com/stacklok/mediator/internal/util"
pb "github.com/stacklok/mediator/pkg/api/protobuf/go/minder/v1"
)
Expand Down Expand Up @@ -57,17 +58,17 @@
}

type repoCache struct {
cache map[string]RepoQuerier
cache *xsync.MapOf[string, RepoQuerier]
}

func newRepoCache() *repoCache {
return &repoCache{
cache: make(map[string]RepoQuerier),
cache: xsync.NewMapOf[RepoQuerier](),
}
}

func (rc *repoCache) newRepository(ecoConfig *ecosystemConfig) (RepoQuerier, error) {
if repo, exists := rc.cache[ecoConfig.Name]; exists {
if repo, exists := rc.cache.Load(ecoConfig.Name); exists {
return repo, nil
}

Expand All @@ -83,7 +84,7 @@
return nil, fmt.Errorf("unknown ecosystem: %s", ecoConfig.Name)
}

rc.cache[ecoConfig.Name] = repo
rc.cache.Store(ecoConfig.Name, repo)
return repo, nil
}

Expand Down
Loading