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

insights: determine if query targets a single repo#39382

Merged
chwarwick merged 2 commits into
mainfrom
cw/count-query-repos
Jul 26, 2022
Merged

insights: determine if query targets a single repo#39382
chwarwick merged 2 commits into
mainfrom
cw/count-query-repos

Conversation

@chwarwick

Copy link
Copy Markdown
Contributor

Adds a new function to the insights query builder package that can determine if a query is targeting a single repo. This will initially be used as one piece of criteria to determine if a search query is eligible to run additional queries to provide additional insights such as % change over time or a small preview of an insight.

Currently only supports queries with a 1 step query plan.

resolves #39241

Test plan

added unit tests pass

@chwarwick chwarwick requested a review from a team July 25, 2022 19:14
@cla-bot cla-bot Bot added the cla-signed label Jul 25, 2022
@sourcegraph-bot

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 98c48b2...88b0a57.

Notify File(s)
@sourcegraph/code-insights-backend enterprise/internal/insights/query/querybuilder/builder.go
enterprise/internal/insights/query/querybuilder/builder_test.go

var QueryNotSupported = errors.New("query not supported")

// IsSingleRepoQuery - Returns a boolean indicating if the query provided targets only a single repo.
// At this time only queries with a single query plan step are supported. Queries with multiple plan steps

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean something like repo:A thing OR repo:B thing won't work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coury-clark at this point that query would kick back the QueryNotSupported error (probably a better name available for that). The issue with repo:A thing OR repo:B thing is that parsing it returns back a 2 step query plan where each step targets a single repo:

  1. repo:a thing
  2. repo:b thing

For simplicity in this first version I made the decision to halt processing on any multi step query plans as unsupported. We could introduce additional logic to check that each step is single repo AND that it is the same repo, I believe that would be simple but I didn't want to get too deep into possibilities of what could occur in more complex query plans.

The following query repo:a thing OR thing2 returns back a single step so something similar to that would not have the same issue.

@chwarwick chwarwick merged commit 0f438a4 into main Jul 26, 2022
@chwarwick chwarwick deleted the cw/count-query-repos branch July 26, 2022 17:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

insights: determine if a search query would execute against a single repo

3 participants