search: refactor to expose context and settings before processing args
Created by: rvantonder
(Sigh, typing this up again)
Before this PR:
- We did some work parsing queries and processing pagination requests in the
Search
function before calling any of the search resolvers implementing methods:
type SearchImplementer interface {
Results(context.Context) (*SearchResultsResolver, error)
Suggestions(context.Context, *searchSuggestionsArgs) ([]*searchSuggestionResolver, error)
Stats(context.Context) (*searchResultsStats, error)
}
The problem is that we don't have a handle to context
in the Search function, meaning that adding any flags to control parsing, or query options, or pagination (or things we might add in future) is ugly and hard to add to user/org/global settings.
After this PR:
The logic we do in Search
is moved to a common function setup(ctx)
that is called by each of the three methods above. But now, we have a handle to ctx
and can case out on settings before parsing (or anything else). This had some follow-on changes (which are generally nice):
-
No need to have alerts implement the
searchResolver
interface (which was previously necessary when returning alerts from theSearch
function). Now we can just wrap in in aSearchResultsResolver
like we elsewhere. -
We can remove references to
originalQuery
and reference search args directly, which is propagated in the resolver now. -
Allows for a user/org/site flag, see #12088 (still WIP)
Open question: I'm not sure that setup
is a great name for this method. Alternatives?
Merge request reports
Activity
Created by: codecov[bot]
Codecov Report
Merging #12086 into master will decrease coverage by
2.24%
. The diff coverage is45.16%
.@@ Coverage Diff @@ ## master #12086 +/- ## ========================================== - Coverage 50.13% 47.89% -2.25% ========================================== Files 1516 1412 -104 Lines 88577 80250 -8327 Branches 6664 6664 ========================================== - Hits 44412 38434 -5978 + Misses 40221 38216 -2005 + Partials 3944 3600 -344
Flag Coverage Δ #go 52.08% <45.16%> (-2.47%)
#storybook 11.66% <ø> (ø)
#typescript 36.78% <ø> (ø)
#unit 47.39% <45.16%> (-2.30%)
Impacted Files Coverage Δ cmd/frontend/graphqlbackend/search_suggestions.go 72.00% <20.00%> (-1.19%)
cmd/frontend/graphqlbackend/search_results.go 43.66% <42.85%> (+1.30%)
cmd/frontend/graphqlbackend/search_alert.go 28.09% <50.00%> (-0.70%)
cmd/frontend/graphqlbackend/search.go 68.09% <100.00%> (+1.37%)
cmd/frontend/db/orgs_mock.go 0.00% <0.00%> (-100.00%)
cmd/frontend/db/users_mock.go 0.00% <0.00%> (-100.00%)
internal/extsvc/github/codehost.go 0.00% <0.00%> (-100.00%)
internal/extsvc/gitlab/codehost.go 0.00% <0.00%> (-100.00%)
...de-intel-worker/internal/correlation/lsif/types.go 0.00% <0.00%> (-100.00%)
internal/authz/bitbucketserver/authz.go 0.00% <0.00%> (-89.48%)
... and 266 more