Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
search: factor out args.Mode dependency deep in call chain (#26625)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvantonder authored Oct 26, 2021
1 parent 576a3af commit 0606072
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cmd/frontend/graphqlbackend/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ func (r *searchResolver) suggestFilePaths(ctx context.Context, limit int) ([]Sea

args.Repos = resolved.RepoRevs

zoektArgs, err := zoektutil.NewIndexedSearchRequest(ctx, &args, search.TextRequest, func([]*search.RepositoryRevisions) {})
globalSearch := args.Mode == search.ZoektGlobalSearch
zoektArgs, err := zoektutil.NewIndexedSearchRequest(ctx, &args, globalSearch, search.TextRequest, func([]*search.RepositoryRevisions) {})
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/frontend/graphqlbackend/search_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,8 @@ func (r *searchResolver) doResults(ctx context.Context, args *search.TextParamet
ctx, stream, cleanup := streaming.WithLimit(ctx, agg, int(argsIndexed.PatternInfo.FileMatchLimit))
defer cleanup()

zoektArgs, err := zoekt.NewIndexedSearchRequest(ctx, &argsIndexed, search.TextRequest, zoekt.MissingRepoRevStatus(stream))
globalSearch := argsIndexed.Mode == search.ZoektGlobalSearch
zoektArgs, err := zoekt.NewIndexedSearchRequest(ctx, &argsIndexed, globalSearch, search.TextRequest, zoekt.MissingRepoRevStatus(stream))
if err != nil {
agg.Error(err)
return
Expand Down Expand Up @@ -1622,7 +1623,8 @@ func (r *searchResolver) doResults(ctx context.Context, args *search.TextParamet
ctx, stream, cleanup := streaming.WithLimit(ctx, agg, int(args.PatternInfo.FileMatchLimit))
defer cleanup()

zoektArgs, err := zoekt.NewIndexedSearchRequest(ctx, args, search.TextRequest, zoekt.MissingRepoRevStatus(stream))
globalSearch := args.Mode == search.ZoektGlobalSearch
zoektArgs, err := zoekt.NewIndexedSearchRequest(ctx, args, globalSearch, search.TextRequest, zoekt.MissingRepoRevStatus(stream))
if err != nil {
agg.Error(err)
return
Expand Down
3 changes: 2 additions & 1 deletion internal/search/run/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ func reposContainingPath(ctx context.Context, args *search.TextParameters, repos
newArgs.Query = q
newArgs.UseFullDeadline = true

zoektArgs, err := zoektutil.NewIndexedSearchRequest(ctx, &newArgs, search.TextRequest, func([]*search.RepositoryRevisions) {})
globalSearch := newArgs.Mode == search.ZoektGlobalSearch
zoektArgs, err := zoektutil.NewIndexedSearchRequest(ctx, &newArgs, globalSearch, search.TextRequest, func([]*search.RepositoryRevisions) {})
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/search/symbol/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func Search(ctx context.Context, args *search.TextParameters, limit int, stream
ctx, stream, cancel := streaming.WithLimit(ctx, stream, limit)
defer cancel()

request, err := zoektutil.NewIndexedSearchRequest(ctx, args, search.SymbolRequest, zoektutil.MissingRepoRevStatus(stream))
globalSearch := args.Mode == search.ZoektGlobalSearch
request, err := zoektutil.NewIndexedSearchRequest(ctx, args, globalSearch, search.SymbolRequest, zoektutil.MissingRepoRevStatus(stream))
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/search/unindexed/structural.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func NewRepoFetcher(stream streaming.Sender, args *search.TextParameters) RepoFe
// allows parameterizing the request to specify a context, for when multiple
// Get() calls are required with different limits or timeouts.
func (r *RepoFetcher) Get(ctx context.Context) ([]repoData, error) {
request, err := zoektutil.NewIndexedSearchRequest(ctx, r.args, search.TextRequest, r.onMissingRepoRevs)
globalSearch := r.args.Mode == search.ZoektGlobalSearch
request, err := zoektutil.NewIndexedSearchRequest(ctx, r.args, globalSearch, search.TextRequest, r.onMissingRepoRevs)
if err != nil {
return nil, err
}
Expand Down
13 changes: 9 additions & 4 deletions internal/search/unindexed/unindexed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func TestSearchFilesInRepos(t *testing.T) {
SearcherURLs: endpoint.Static("test"),
}

zoektArgs, err := zoektutil.NewIndexedSearchRequest(context.Background(), args, search.TextRequest, func([]*search.RepositoryRevisions) {})
globalSearch := args.Mode == search.ZoektGlobalSearch
zoektArgs, err := zoektutil.NewIndexedSearchRequest(context.Background(), args, globalSearch, search.TextRequest, func([]*search.RepositoryRevisions) {})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -138,7 +139,8 @@ func TestSearchFilesInRepos(t *testing.T) {
SearcherURLs: endpoint.Static("test"),
}

zoektArgs, err = zoektutil.NewIndexedSearchRequest(context.Background(), args, search.TextRequest, func([]*search.RepositoryRevisions) {})
globalSearch = args.Mode == search.ZoektGlobalSearch
zoektArgs, err = zoektutil.NewIndexedSearchRequest(context.Background(), args, globalSearch, search.TextRequest, func([]*search.RepositoryRevisions) {})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -213,7 +215,8 @@ func TestSearchFilesInReposStream(t *testing.T) {
SearcherURLs: endpoint.Static("test"),
}

zoektArgs, err := zoektutil.NewIndexedSearchRequest(context.Background(), args, search.TextRequest, func([]*search.RepositoryRevisions) {})
globalSearch := args.Mode == search.ZoektGlobalSearch
zoektArgs, err := zoektutil.NewIndexedSearchRequest(context.Background(), args, globalSearch, search.TextRequest, func([]*search.RepositoryRevisions) {})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -293,7 +296,9 @@ func TestSearchFilesInRepos_multipleRevsPerRepo(t *testing.T) {
args.Repos[0].ListRefs = func(context.Context, api.RepoName) ([]git.Ref, error) {
return []git.Ref{{Name: "refs/heads/branch3"}, {Name: "refs/heads/branch4"}}, nil
}
zoektArgs, err := zoektutil.NewIndexedSearchRequest(context.Background(), args, search.TextRequest, func([]*search.RepositoryRevisions) {})

globalSearch := args.Mode == search.ZoektGlobalSearch
zoektArgs, err := zoektutil.NewIndexedSearchRequest(context.Background(), args, globalSearch, search.TextRequest, func([]*search.RepositoryRevisions) {})
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/search/zoekt/indexed_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func fallbackUnindexed(repos []*search.RepositoryRevisions, limit int, onMissing
}
}

func NewIndexedSearchRequest(ctx context.Context, args *search.TextParameters, typ search.IndexedRequestType, onMissing OnMissingRepoRevs) (IndexedSearchRequest, error) {
func NewIndexedSearchRequest(ctx context.Context, args *search.TextParameters, globalSearch bool, typ search.IndexedRequestType, onMissing OnMissingRepoRevs) (IndexedSearchRequest, error) {
// If Zoekt is disabled just fallback to Unindexed.
if args.Zoekt == nil {
if args.PatternInfo.Index == query.Only {
Expand Down Expand Up @@ -234,7 +234,7 @@ func NewIndexedSearchRequest(ctx context.Context, args *search.TextParameters, t
Zoekt: args.Zoekt,
}

if args.Mode == search.ZoektGlobalSearch {
if globalSearch {
// performance: optimize global searches where Zoekt searches
// all shards anyway.
return newIndexedUniverseSearchRequest(ctx, zoektArgs, args.RepoOptions, args.UserPrivateRepos)
Expand Down
2 changes: 2 additions & 0 deletions internal/search/zoekt/indexed_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@ func TestIndexedSearch(t *testing.T) {
Zoekt: zoektArgs.Zoekt,
}

globalSearch := args.Mode == search.ZoektGlobalSearch
indexed, err := NewIndexedSearchRequest(
context.Background(),
args,
globalSearch,
search.TextRequest,
MissingRepoRevStatus(streaming.StreamFunc(func(streaming.SearchEvent) {})),
)
Expand Down

0 comments on commit 0606072

Please sign in to comment.