Skip to content

Commit

Permalink
Don't recreate scorecard clients multiple times
Browse files Browse the repository at this point in the history
Signed-off-by: Raghav Kaul <[email protected]>
  • Loading branch information
raghavkaul authored and jeffmendoza committed Jan 5, 2024
1 parent 968a887 commit b9a43c0
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/scorecard/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,16 @@ func Get(ctx context.Context, fullRepo string, tr http.RoundTripper) (*ScClient,
} else {
mMutex.RUnlock()
}
mMutex.RLock()
mMutex.Lock()
if scc, ok := scClients[fullRepo]; ok {
mMutex.RUnlock()
mMutex.Unlock()
return scc, nil
}
mMutex.RUnlock()
scc, err := create(ctx, fullRepo, tr)
if err != nil {
mMutex.Unlock()
return nil, err
}
mMutex.Lock()
scClients[fullRepo] = scc
mMutex.Unlock()
return scc, nil
Expand Down

0 comments on commit b9a43c0

Please sign in to comment.