From d0e437640a99657c4bc0f38ef4c9d594009a9ca6 Mon Sep 17 00:00:00 2001 From: Quinn Slack Date: Wed, 19 Jun 2024 21:24:45 -0400 Subject: [PATCH] apply ^github.com optimization for all instances The purpose of this change is to remove a special-case for Sourcegraph.com. If a user's query has a repo filter like `repo:github.com/foo`, we rewrite it to `repo:^github.com/foo` (note the `^`). This makes the DB query faster because it only needs to search at the beginning of the string. This optimization only happens on Sourcegraph.com because technically someone could have a repo at (say) `https://github.com/owner/foo.github.com` or `https://myothercodehost.example.com/foo.github.com/bar`, and they could query `repo:github.com` intending to match one of those. We wanted to avoid that behavior on customer instances. Those are rare edge cases, and the user could work around this rewriting with `repo:.*github.com` if truly needed. We now make this rewriting only occur if there is a trailing slash, which mitigates the (anyway likely zero) impact. Making this rewriting behavior consistent removes a dotcom edge case and could improve repository search performance for common queries with a tiny hypothetical impact on the behavior. Note that GitHub Pages repositories are not affected here because those are named `foo.github.io` not `foo.github.com` (https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site#creating-a-repository-for-your-site). --- internal/search/repos/BUILD.bazel | 1 - internal/search/repos/repos.go | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/search/repos/BUILD.bazel b/internal/search/repos/BUILD.bazel index 9db479ece218..aa9f03f67825 100644 --- a/internal/search/repos/BUILD.bazel +++ b/internal/search/repos/BUILD.bazel @@ -15,7 +15,6 @@ go_library( "//internal/api", "//internal/conf", "//internal/database", - "//internal/dotcom", "//internal/endpoint", "//internal/gitserver", "//internal/gitserver/gitdomain", diff --git a/internal/search/repos/repos.go b/internal/search/repos/repos.go index 842d2d3d700f..be4a5b933256 100644 --- a/internal/search/repos/repos.go +++ b/internal/search/repos/repos.go @@ -22,7 +22,6 @@ import ( "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/conf" "github.com/sourcegraph/sourcegraph/internal/database" - "github.com/sourcegraph/sourcegraph/internal/dotcom" "github.com/sourcegraph/sourcegraph/internal/endpoint" "github.com/sourcegraph/sourcegraph/internal/gitserver" "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" @@ -1117,7 +1116,7 @@ func findPatternRevs(includePatterns []query.ParsedRepoFilter) (outputPatterns [ } func optimizeRepoPatternWithHeuristics(repoPattern string) string { - if dotcom.SourcegraphDotComMode() && (strings.HasPrefix(repoPattern, "github.com") || strings.HasPrefix(repoPattern, `github\.com`)) { + if strings.HasPrefix(repoPattern, "github.com/") || strings.HasPrefix(repoPattern, `github\.com/`) { repoPattern = "^" + repoPattern } // Optimization: make the "." in "github.com" a literal dot