Skip to content

Commit

Permalink
Making the removal from cache in the same lock as the update (#595)
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <shawn@hurley.page>
  • Loading branch information
shawn-hurley authored Jan 29, 2025
1 parent 0201c70 commit de6ca2e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions kai_analyzer_rpc/pkg/service/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ func (a *Analyzer) Analyze(args Args, response *Response) error {
a.setCache(rulesets)
} else {
a.Logger.V(5).Info("updating cache for filepath", "paths", args.IncludedPaths)
a.invlaidateCachePerFile(args.IncludedPaths)
a.updateCache(rulesets)
a.updateCache(rulesets, args.IncludedPaths)
}

// Now we need to invalidate anything, from the files in included paths
Expand All @@ -182,12 +181,15 @@ func (a *Analyzer) setCache(rulesets []konveyor.RuleSet) {
a.cache = map[string][]cacheValue{}
a.cacheMutex.Unlock()

a.updateCache(rulesets)
a.updateCache(rulesets, nil)
}

func (a *Analyzer) updateCache(rulesets []konveyor.RuleSet) {
func (a *Analyzer) updateCache(rulesets []konveyor.RuleSet, includedPaths []string) {
a.cacheMutex.Lock()
defer a.cacheMutex.Unlock()
if includedPaths != nil {
a.invalidateCachePerFile(includedPaths)
}

for _, r := range rulesets {
for violationName, v := range r.Violations {
Expand Down Expand Up @@ -236,9 +238,7 @@ func (a *Analyzer) updateCache(rulesets []konveyor.RuleSet) {
}
}

func (a *Analyzer) invlaidateCachePerFile(paths []string) {
a.cacheMutex.Lock()
defer a.cacheMutex.Unlock()
func (a *Analyzer) invalidateCachePerFile(paths []string) {
for _, p := range paths {
a.Logger.Info("deleting cache entry for path", "path", p)
delete(a.cache, p)
Expand Down

0 comments on commit de6ca2e

Please sign in to comment.