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

Commit f72eaa7

Browse files
authored
Search chore: tidy up dependencies on symbol search (#57576)
This contains a bunch of cleanups of search symbols code. Basically, the goal was to take all the global clients used by symbols and explicitly declare them in a new ZoektSymbolsClient. In order to limit the scope of this change, I added a new DefaultZoektSymbolsClient so that the things that expect to be able to call this stuff without dependencies still can.
1 parent a9a1cef commit f72eaa7

File tree

14 files changed

+148
-153
lines changed

14 files changed

+148
-153
lines changed

cmd/frontend/backend/BUILD.bazel

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ go_library(
1313
"mocks_temp.go",
1414
"repos.go",
1515
"repos_mock.go",
16-
"symbols.go",
1716
"trace.go",
1817
"user_emails.go",
1918
"users.go",
@@ -56,9 +55,6 @@ go_library(
5655
"//internal/repos",
5756
"//internal/repoupdater",
5857
"//internal/repoupdater/protocol",
59-
"//internal/search",
60-
"//internal/search/result",
61-
"//internal/symbols",
6258
"//internal/trace",
6359
"//internal/txemail",
6460
"//internal/txemail/txtypes",

cmd/frontend/backend/symbols.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

cmd/frontend/graphqlbackend/repository_stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (r *repositoryStatsResolver) IndexedLinesCount(ctx context.Context) (BigInt
7171

7272
func (r *repositoryStatsResolver) computeIndexedStats(ctx context.Context) (int32, int64, error) {
7373
r.indexedStatsOnce.Do(func() {
74-
repos, err := search.ListAllIndexed(ctx)
74+
repos, err := search.ListAllIndexed(ctx, search.Indexed())
7575
if err != nil {
7676
r.indexedStatsErr = err
7777
return

cmd/frontend/graphqlbackend/symbols.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
88
"github.com/sourcegraph/sourcegraph/internal/api"
9-
"github.com/sourcegraph/sourcegraph/internal/authz"
109
"github.com/sourcegraph/sourcegraph/internal/database"
1110
"github.com/sourcegraph/sourcegraph/internal/gitserver"
1211
"github.com/sourcegraph/sourcegraph/internal/search/result"
@@ -20,7 +19,7 @@ type symbolsArgs struct {
2019
}
2120

2221
func (r *GitTreeEntryResolver) Symbols(ctx context.Context, args *symbolsArgs) (*symbolConnectionResolver, error) {
23-
symbols, err := symbol.Compute(ctx, authz.DefaultSubRepoPermsChecker, r.commit.repoResolver.RepoMatch.RepoName(), api.CommitID(r.commit.oid), r.commit.inputRev, args.Query, args.First, args.IncludePatterns)
22+
symbols, err := symbol.DefaultZoektSymbolsClient().Compute(ctx, r.commit.repoResolver.RepoMatch.RepoName(), api.CommitID(r.commit.oid), r.commit.inputRev, args.Query, args.First, args.IncludePatterns)
2423
if err != nil && len(symbols) == 0 {
2524
return nil, err
2625
}
@@ -34,15 +33,15 @@ func (r *GitTreeEntryResolver) Symbol(ctx context.Context, args *struct {
3433
Line int32
3534
Character int32
3635
}) (*symbolResolver, error) {
37-
symbolMatch, err := symbol.GetMatchAtLineCharacter(ctx, authz.DefaultSubRepoPermsChecker, r.commit.repoResolver.RepoMatch.RepoName(), api.CommitID(r.commit.oid), r.Path(), int(args.Line), int(args.Character))
36+
symbolMatch, err := symbol.DefaultZoektSymbolsClient().GetMatchAtLineCharacter(ctx, r.commit.repoResolver.RepoMatch.RepoName(), api.CommitID(r.commit.oid), r.Path(), int(args.Line), int(args.Character))
3837
if err != nil || symbolMatch == nil {
3938
return nil, err
4039
}
4140
return &symbolResolver{r.db, r.commit, symbolMatch}, nil
4241
}
4342

4443
func (r *GitCommitResolver) Symbols(ctx context.Context, args *symbolsArgs) (*symbolConnectionResolver, error) {
45-
symbols, err := symbol.Compute(ctx, authz.DefaultSubRepoPermsChecker, r.repoResolver.RepoMatch.RepoName(), api.CommitID(r.oid), r.inputRev, args.Query, args.First, args.IncludePatterns)
44+
symbols, err := symbol.DefaultZoektSymbolsClient().Compute(ctx, r.repoResolver.RepoMatch.RepoName(), api.CommitID(r.oid), r.inputRev, args.Query, args.First, args.IncludePatterns)
4645
if err != nil && len(symbols) == 0 {
4746
return nil, err
4847
}

cmd/frontend/internal/app/ui/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ go_library(
3636
"//cmd/frontend/internal/search",
3737
"//internal/api",
3838
"//internal/auth/userpasswd",
39-
"//internal/authz",
4039
"//internal/conf",
4140
"//internal/conf/deploy",
4241
"//internal/cookie",

cmd/frontend/internal/app/ui/handlers.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/routevar"
2929
"github.com/sourcegraph/sourcegraph/internal/api"
3030
"github.com/sourcegraph/sourcegraph/internal/auth/userpasswd"
31-
"github.com/sourcegraph/sourcegraph/internal/authz"
3231
"github.com/sourcegraph/sourcegraph/internal/conf"
3332
"github.com/sourcegraph/sourcegraph/internal/conf/deploy"
3433
"github.com/sourcegraph/sourcegraph/internal/cookie"
@@ -276,9 +275,8 @@ func newCommon(w http.ResponseWriter, r *http.Request, db database.DB, title str
276275
ctx, cancel := context.WithTimeout(r.Context(), time.Second*1)
277276
defer cancel()
278277

279-
if symbolMatch, _ := symbol.GetMatchAtLineCharacter(
278+
if symbolMatch, _ := symbol.DefaultZoektSymbolsClient().GetMatchAtLineCharacter(
280279
ctx,
281-
authz.DefaultSubRepoPermsChecker,
282280
types.MinimalRepo{ID: common.Repo.ID, Name: common.Repo.Name},
283281
common.CommitID,
284282
strings.TrimLeft(blobPath, "/"),

cmd/worker/internal/zoektrepos/zoektrepos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var (
6262
)
6363

6464
func (h *handler) Handle(ctx context.Context) error {
65-
indexed, err := search.ListAllIndexed(ctx)
65+
indexed, err := search.ListAllIndexed(ctx, search.Indexed())
6666
if err != nil {
6767
return err
6868
}

internal/search/env.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ var (
3030

3131
indexedDialerOnce sync.Once
3232
indexedDialer backend.ZoektDialer
33-
34-
IndexedMock zoekt.Streamer
3533
)
3634

3735
func SearcherURLs() *endpoint.Map {
@@ -53,9 +51,6 @@ func SearcherGRPCConnectionCache() *defaults.ConnectionCache {
5351
}
5452

5553
func Indexed() zoekt.Streamer {
56-
if IndexedMock != nil {
57-
return IndexedMock
58-
}
5954
indexedSearchOnce.Do(func() {
6055
indexedSearch = backend.NewCachedSearcher(conf.Get().ServiceConnections().ZoektListTTL, backend.NewMeteredSearcher(
6156
"", // no hostname means its the aggregator
@@ -79,11 +74,11 @@ type ZoektAllIndexed struct {
7974
}
8075

8176
// ListAllIndexed lists all indexed repositories.
82-
func ListAllIndexed(ctx context.Context) (*ZoektAllIndexed, error) {
77+
func ListAllIndexed(ctx context.Context, zs zoekt.Searcher) (*ZoektAllIndexed, error) {
8378
q := &query.Const{Value: true}
8479
opts := &zoekt.ListOptions{Field: zoekt.RepoListFieldReposMap}
8580

86-
repos, err := Indexed().List(ctx, q, opts)
81+
repos, err := zs.List(ctx, q, opts)
8782
if err != nil {
8883
return nil, err
8984
}

internal/search/searcher/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ go_library(
1313
importpath = "github.com/sourcegraph/sourcegraph/internal/search/searcher",
1414
visibility = ["//:__subpackages__"],
1515
deps = [
16-
"//cmd/frontend/backend",
1716
"//cmd/searcher/protocol",
1817
"//internal/api",
1918
"//internal/conf",
@@ -29,6 +28,7 @@ go_library(
2928
"//internal/search/streaming",
3029
"//internal/search/streaming/http",
3130
"//internal/searcher/v1:searcher",
31+
"//internal/symbols",
3232
"//internal/trace",
3333
"//internal/types",
3434
"//lib/errors",

internal/search/searcher/symbol_search_job.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
"github.com/sourcegraph/conc/pool"
88
"go.opentelemetry.io/otel/attribute"
99

10-
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
1110
"github.com/sourcegraph/sourcegraph/internal/api"
1211
"github.com/sourcegraph/sourcegraph/internal/conf"
1312
"github.com/sourcegraph/sourcegraph/internal/gitserver"
1413
"github.com/sourcegraph/sourcegraph/internal/search"
1514
"github.com/sourcegraph/sourcegraph/internal/search/job"
1615
"github.com/sourcegraph/sourcegraph/internal/search/result"
1716
"github.com/sourcegraph/sourcegraph/internal/search/streaming"
17+
"github.com/sourcegraph/sourcegraph/internal/symbols"
1818
"github.com/sourcegraph/sourcegraph/internal/trace"
1919
"github.com/sourcegraph/sourcegraph/internal/types"
2020
)
@@ -103,7 +103,7 @@ func searchInRepo(ctx context.Context, gitserverClient gitserver.Client, repoRev
103103
}
104104
tr.SetAttributes(commitID.Attr())
105105

106-
symbols, err := backend.Symbols.ListTags(ctx, search.SymbolsParameters{
106+
symbols, err := symbols.DefaultClient.Search(ctx, search.SymbolsParameters{
107107
Repo: repoRevs.Repo.Name,
108108
CommitID: commitID,
109109
Query: patternInfo.Pattern,
@@ -114,6 +114,13 @@ func searchInRepo(ctx context.Context, gitserverClient gitserver.Client, repoRev
114114
// Ask for limit + 1 so we can detect whether there are more results than the limit.
115115
First: limit + 1,
116116
})
117+
if err != nil {
118+
return nil, err
119+
}
120+
121+
for i := range symbols {
122+
symbols[i].Line += 1 // callers expect 1-indexed lines
123+
}
117124

118125
// All symbols are from the same repo, so we can just partition them by path
119126
// to build file matches

0 commit comments

Comments
 (0)