mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:31:48 +00:00
Cache results of sub-repo perms enabled checks (#53463)
This commit is contained in:
parent
6fdfa61a3b
commit
5c346a9fc3
@ -164,14 +164,6 @@ func canReadPaths(ctx context.Context, checker SubRepoPermissionChecker, repo ap
|
||||
return true, nil
|
||||
}
|
||||
|
||||
enabled, err := SubRepoEnabledForRepo(ctx, checker, repo)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !enabled {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
var checkPathPermsCount int
|
||||
defer func() {
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/job"
|
||||
@ -84,7 +85,34 @@ func applySubRepoFiltering(ctx context.Context, checker authz.SubRepoPermissionC
|
||||
// Filter matches in place
|
||||
filtered := matches[:0]
|
||||
|
||||
subRepoPermsCache := map[api.RepoName]bool{}
|
||||
errCache := map[api.RepoName]struct{}{} // cache repos that errored
|
||||
|
||||
for _, m := range matches {
|
||||
// If the check errored before, skip the repo
|
||||
if _, ok := errCache[m.RepoName().Name]; ok {
|
||||
continue
|
||||
}
|
||||
// Skip check if sub-repo perms are disabled for the repository
|
||||
enabled, ok := subRepoPermsCache[m.RepoName().Name]
|
||||
if ok && !enabled {
|
||||
filtered = append(filtered, m)
|
||||
continue
|
||||
}
|
||||
if !ok {
|
||||
enabled, err := authz.SubRepoEnabledForRepo(ctx, checker, m.RepoName().Name)
|
||||
if err != nil {
|
||||
// If an error occurs while checking sub-repo perms, we omit it from the results
|
||||
logger.Error("Could not determine if sub-repo permissions are enabled for repo, skipping", log.String("repoName", string(m.RepoName().Name)))
|
||||
errCache[m.RepoName().Name] = struct{}{}
|
||||
continue
|
||||
}
|
||||
subRepoPermsCache[m.RepoName().Name] = enabled // cache the result for this repo name
|
||||
if !enabled {
|
||||
filtered = append(filtered, m)
|
||||
continue
|
||||
}
|
||||
}
|
||||
switch mm := m.(type) {
|
||||
case *result.FileMatch:
|
||||
repo := mm.Repo.Name
|
||||
|
||||
Loading…
Reference in New Issue
Block a user