mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 19:51:50 +00:00
search: allow job Run method to accept resolved repos (#26750)
This commit is contained in:
parent
aa68dc1325
commit
4b9df37d88
@ -1658,7 +1658,7 @@ func (r *searchResolver) doResults(ctx context.Context, args *search.TextParamet
|
||||
|
||||
if featureflag.FromContext(ctx).GetBoolOr("cc_commit_search", false) {
|
||||
addCommitSearch := func(diff bool) {
|
||||
j, err := commit.NewSearchJob(args.Query, args.Repos, diff, int(args.PatternInfo.FileMatchLimit))
|
||||
j, err := commit.NewSearchJob(args.Query, diff, int(args.PatternInfo.FileMatchLimit))
|
||||
if err != nil {
|
||||
agg.Error(err)
|
||||
return
|
||||
@ -1719,7 +1719,7 @@ func (r *searchResolver) doResults(ctx context.Context, args *search.TextParamet
|
||||
wg.Add(1)
|
||||
goroutine.Go(func() {
|
||||
defer wg.Done()
|
||||
_ = agg.DoSearch(ctx, job, args.Mode)
|
||||
_ = agg.DoSearch(ctx, job, args.Repos, args.Mode)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -24,23 +24,22 @@ import (
|
||||
|
||||
type CommitSearch struct {
|
||||
Query gitprotocol.Node
|
||||
Repos []*search.RepositoryRevisions
|
||||
Diff bool
|
||||
HasTimeFilter bool
|
||||
Limit int
|
||||
}
|
||||
|
||||
func (j CommitSearch) Run(ctx context.Context, stream streaming.Sender) error {
|
||||
func (j CommitSearch) Run(ctx context.Context, stream streaming.Sender, repos []*search.RepositoryRevisions) error {
|
||||
resultType := "commit"
|
||||
if j.Diff {
|
||||
resultType = "diff"
|
||||
}
|
||||
if err := CheckSearchLimits(j.HasTimeFilter, len(j.Repos), resultType); err != nil {
|
||||
if err := CheckSearchLimits(j.HasTimeFilter, len(repos), resultType); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
g, ctx := errgroup.WithContext(ctx)
|
||||
for _, repoRev := range j.Repos {
|
||||
for _, repoRev := range repos {
|
||||
repoRev := repoRev // we close over repoRev in onMatches
|
||||
|
||||
// Skip the repo if no revisions were resolved for it
|
||||
@ -125,10 +124,9 @@ func HasTimeFilter(q query.Q) bool {
|
||||
return hasTimeFilter
|
||||
}
|
||||
|
||||
func NewSearchJob(q query.Q, repos []*search.RepositoryRevisions, diff bool, limit int) (*CommitSearch, error) {
|
||||
func NewSearchJob(q query.Q, diff bool, limit int) (*CommitSearch, error) {
|
||||
return &CommitSearch{
|
||||
Query: queryToGitQuery(q, diff),
|
||||
Repos: repos,
|
||||
Diff: diff,
|
||||
Limit: limit,
|
||||
HasTimeFilter: HasTimeFilter(q),
|
||||
|
||||
@ -81,7 +81,7 @@ func (a *Aggregator) DoRepoSearch(ctx context.Context, args *search.TextParamete
|
||||
return errors.Wrap(err, "repository search failed")
|
||||
}
|
||||
|
||||
func (a *Aggregator) DoSearch(ctx context.Context, job Job, mode search.GlobalSearchMode) (err error) {
|
||||
func (a *Aggregator) DoSearch(ctx context.Context, job Job, repos []*search.RepositoryRevisions, mode search.GlobalSearchMode) (err error) {
|
||||
tr, ctx := trace.New(ctx, "DoSearch", job.Name())
|
||||
tr.LogFields(trace.Stringer("global_search_mode", mode))
|
||||
defer func() {
|
||||
@ -90,7 +90,7 @@ func (a *Aggregator) DoSearch(ctx context.Context, job Job, mode search.GlobalSe
|
||||
tr.Finish()
|
||||
}()
|
||||
|
||||
err = job.Run(ctx, a)
|
||||
err = job.Run(ctx, a, repos)
|
||||
return errors.Wrap(err, job.Name()+" search failed")
|
||||
|
||||
}
|
||||
|
||||
@ -25,9 +25,11 @@ type SearchInputs struct {
|
||||
// object runs a search. The relation with SearchInputs and Jobs is that
|
||||
// SearchInputs are static values, parsed and validated, to produce Jobs. Jobs
|
||||
// express semantic behavior at runtime across different backends and system
|
||||
// architecture.
|
||||
// architecture. The third argument accepts resolved repositories (which may or
|
||||
// may not be required, depending on the job. E.g., a global search job does not
|
||||
// require upfront repository resolution).
|
||||
type Job interface {
|
||||
Run(context.Context, streaming.Sender) error
|
||||
Run(context.Context, streaming.Sender, []*search.RepositoryRevisions) error
|
||||
Name() string
|
||||
}
|
||||
|
||||
|
||||
@ -182,7 +182,7 @@ type StructuralSearch struct {
|
||||
SearcherArgs search.SearcherParameters
|
||||
}
|
||||
|
||||
func (s *StructuralSearch) Run(ctx context.Context, stream streaming.Sender) error {
|
||||
func (s *StructuralSearch) Run(ctx context.Context, stream streaming.Sender, _ []*search.RepositoryRevisions) error {
|
||||
return runStructuralSearch(ctx, &s.SearcherArgs, &s.RepoFetcher, stream)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user