Skip to content

Commit

Permalink
shards: use selectRepoSet in List (#749)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
keegancsmith authored Mar 26, 2024
1 parent f2577c2 commit 06de7ad
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions shards/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 {
Expand Down

0 comments on commit 06de7ad

Please sign in to comment.