From 06de7adb722e71f0fd38f4bcea416b66cea759ec Mon Sep 17 00:00:00 2001 From: Keegan Carruthers-Smith Date: Tue, 26 Mar 2024 17:06:40 +0200 Subject: [PATCH] shards: use selectRepoSet in List (#749) Currently we have unindexed search asking Zoekt what commit it has for a very specific repository. In normal search we use selectRepoSet to avoid searching shards which are unrelated to the query. This uses the same optimization in List. Test Plan: go test --- shards/shards.go | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/shards/shards.go b/shards/shards.go index 0e3672745..8ec8f2cf0 100644 --- a/shards/shards.go +++ b/shards/shards.go @@ -919,7 +919,31 @@ func (ss *shardedSearcher) List(ctx context.Context, r query.Q, opts *zoekt.List tr.LazyPrintf("acquired process") loaded := ss.getLoaded() - shards := loaded.shards + + // Setup what we return now, since we may short circuit if there are no + // shards to search. + stillLoadingCrashes := 0 + if !loaded.ready { + // We may have missed results due to not being fully loaded. + stillLoadingCrashes++ + } + agg := zoekt.RepoList{ + Crashes: stillLoadingCrashes, + ReposMap: zoekt.ReposMap{}, + Repos: []*zoekt.RepoListEntry{}, + } + + // PERF: Select the subset of shards that we will search over for the given + // query. A common List query only asks for a specific repo, so this is an + // important optimization. + tr.LazyPrintf("before selectRepoSet shards:%d", len(loaded.shards)) + shards, r := selectRepoSet(loaded.shards, r) + tr.LazyPrintf("after selectRepoSet shards:%d %s", len(shards), r) + + if len(shards) == 0 { + return &agg, nil + } + shardCount := len(shards) all := make(chan shardListResult, shardCount) tr.LazyPrintf("shardCount: %d", len(shards)) @@ -938,17 +962,6 @@ func (ss *shardedSearcher) List(ctx context.Context, r query.Q, opts *zoekt.List }() } - stillLoadingCrashes := 0 - if !loaded.ready { - // We may have missed results due to not being fully loaded. - stillLoadingCrashes++ - } - - agg := zoekt.RepoList{ - Crashes: stillLoadingCrashes, - ReposMap: zoekt.ReposMap{}, - } - uniq := map[string]*zoekt.RepoListEntry{} for range shards {