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

Commit d0e4376

Browse files
committed
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).
1 parent fee9116 commit d0e4376

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

internal/search/repos/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ go_library(
1515
"//internal/api",
1616
"//internal/conf",
1717
"//internal/database",
18-
"//internal/dotcom",
1918
"//internal/endpoint",
2019
"//internal/gitserver",
2120
"//internal/gitserver/gitdomain",

internal/search/repos/repos.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/sourcegraph/sourcegraph/internal/api"
2323
"github.com/sourcegraph/sourcegraph/internal/conf"
2424
"github.com/sourcegraph/sourcegraph/internal/database"
25-
"github.com/sourcegraph/sourcegraph/internal/dotcom"
2625
"github.com/sourcegraph/sourcegraph/internal/endpoint"
2726
"github.com/sourcegraph/sourcegraph/internal/gitserver"
2827
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
@@ -1117,7 +1116,7 @@ func findPatternRevs(includePatterns []query.ParsedRepoFilter) (outputPatterns [
11171116
}
11181117

11191118
func optimizeRepoPatternWithHeuristics(repoPattern string) string {
1120-
if dotcom.SourcegraphDotComMode() && (strings.HasPrefix(repoPattern, "github.com") || strings.HasPrefix(repoPattern, `github\.com`)) {
1119+
if strings.HasPrefix(repoPattern, "github.com/") || strings.HasPrefix(repoPattern, `github\.com/`) {
11211120
repoPattern = "^" + repoPattern
11221121
}
11231122
// Optimization: make the "." in "github.com" a literal dot

0 commit comments

Comments
 (0)