Skip to content

Commit

Permalink
all: remove deprecated RepoList.Minimal
Browse files Browse the repository at this point in the history
This field is no longer requested in Sourcegraph and has been deprecated
for a while.

Test Plan: go test ./...
  • Loading branch information
keegancsmith committed Jul 18, 2023
1 parent 1d71fd0 commit 80aef13
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 539 deletions.
22 changes: 6 additions & 16 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,6 @@ type RepoList struct {
// Returned when ListOptions.Field is RepoListFieldRepos.
Repos []*RepoListEntry

// Returned when ListOptions.Field is RepoListFieldMinimal.
//
// Deprecated: use ReposMap.
Minimal map[uint32]*MinimalRepoListEntry

// ReposMap is set when ListOptions.Field is RepoListFieldReposMap.
ReposMap ReposMap

Expand All @@ -830,16 +825,10 @@ type RepoListField int

const (
RepoListFieldRepos RepoListField = 0
RepoListFieldMinimal = 1
RepoListFieldReposMap = 2
)

type ListOptions struct {
// Return only Minimal data per repo that Sourcegraph frontend needs.
//
// Deprecated: use Field
Minimal bool

// Field decides which field to populate in RepoList response.
Field RepoListField
}
Expand All @@ -848,13 +837,14 @@ func (o *ListOptions) GetField() (RepoListField, error) {
if o == nil {
return RepoListFieldRepos, nil
}
if o.Field < 0 || o.Field > RepoListFieldReposMap {
switch o.Field {
case RepoListFieldRepos, RepoListFieldReposMap:
return o.Field, nil
case 1:
return 0, fmt.Errorf("RepoListFieldMinimal (%d) is no longer supported", o.Field)
default:
return 0, fmt.Errorf("unknown RepoListField %d", o.Field)
}
if o.Minimal == true {
return RepoListFieldMinimal, nil
}
return o.Field, nil
}

func (o *ListOptions) String() string {
Expand Down
23 changes: 2 additions & 21 deletions api_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,18 +599,11 @@ func RepoListFromProto(p *proto.ListResponse) *RepoList {
reposMap[id] = MinimalRepoListEntryFromProto(mle)
}

minimal := make(map[uint32]*MinimalRepoListEntry, len(p.GetMinimal()))
for id, mle := range p.GetMinimal() {
m := MinimalRepoListEntryFromProto(mle)
minimal[id] = &m
}

return &RepoList{
Repos: repos,
ReposMap: reposMap,
Crashes: int(p.GetCrashes()),
Stats: RepoStatsFromProto(p.GetStats()),
Minimal: minimal,
}
}

Expand All @@ -625,17 +618,11 @@ func (r *RepoList) ToProto() *proto.ListResponse {
reposMap[id] = repo.ToProto()
}

minimal := make(map[uint32]*proto.MinimalRepoListEntry, len(r.Minimal))
for id, repo := range r.Minimal {
minimal[id] = repo.ToProto()
}

return &proto.ListResponse{
Repos: []*proto.RepoListEntry{},
ReposMap: reposMap,
Crashes: int64(r.Crashes),
Stats: r.Stats.ToProto(),
Minimal: minimal,
}
}

Expand All @@ -647,15 +634,12 @@ func (l *ListOptions) ToProto() *proto.ListOptions {
switch l.Field {
case RepoListFieldRepos:
field = proto.ListOptions_REPO_LIST_FIELD_REPOS
case RepoListFieldMinimal:
field = proto.ListOptions_REPO_LIST_FIELD_MINIMAL
case RepoListFieldReposMap:
field = proto.ListOptions_REPO_LIST_FIELD_REPOS_MAP
}

return &proto.ListOptions{
Field: field,
Minimal: l.Minimal,
Field: field,
}
}

Expand All @@ -667,14 +651,11 @@ func ListOptionsFromProto(p *proto.ListOptions) *ListOptions {
switch p.GetField() {
case proto.ListOptions_REPO_LIST_FIELD_REPOS:
field = RepoListFieldRepos
case proto.ListOptions_REPO_LIST_FIELD_MINIMAL:
field = RepoListFieldMinimal
case proto.ListOptions_REPO_LIST_FIELD_REPOS_MAP:
field = RepoListFieldReposMap
}
return &ListOptions{
Field: field,
Minimal: p.GetMinimal(),
Field: field,
}
}

Expand Down
7 changes: 2 additions & 5 deletions api_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,9 @@ func (*Repository) Generate(rng *rand.Rand, _ int) reflect.Value {
}

func (RepoListField) Generate(rng *rand.Rand, _ int) reflect.Value {
switch rng.Int() % 3 {
case 0:
if rng.Intn(2) == 0 {
return reflect.ValueOf(RepoListField(RepoListFieldRepos))
case 1:
return reflect.ValueOf(RepoListField(RepoListFieldMinimal))
default:
} else {
return reflect.ValueOf(RepoListField(RepoListFieldReposMap))
}
}
Expand Down
14 changes: 3 additions & 11 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func (d *indexData) scoreFileUsingBM25(fileMatch *FileMatch, doc uint32, cands [
// bytes should work fine, as we're just computing a ratio.
fileLength := float64(d.boundaries[doc+1] - d.boundaries[doc])
numFiles := len(d.boundaries)
averageFileLength := float64(d.boundaries[numFiles - 1]) / float64(numFiles)
averageFileLength := float64(d.boundaries[numFiles-1]) / float64(numFiles)
L := fileLength / averageFileLength

// Use standard parameter defaults (used in Lucene and academic papers)
Expand All @@ -492,7 +492,7 @@ func (d *indexData) scoreFileUsingBM25(fileMatch *FileMatch, doc uint32, cands [
for _, freq := range termFreqs {
tf := float64(freq)
sumTf += tf
score += ((k + 1.0) * tf) / (k * (1.0 - b + b * L) + tf)
score += ((k + 1.0) * tf) / (k*(1.0-b+b*L) + tf)
}

fileMatch.addKeywordScore(score, sumTf, L, opts.DebugScore)
Expand Down Expand Up @@ -689,8 +689,6 @@ func (d *indexData) List(ctx context.Context, q query.Q, opts *ListOptions) (rl
switch field {
case RepoListFieldRepos:
l.Repos = make([]*RepoListEntry, 0, len(d.repoListEntry))
case RepoListFieldMinimal:
l.Minimal = make(map[uint32]*MinimalRepoListEntry, len(d.repoListEntry))
case RepoListFieldReposMap:
l.ReposMap = make(ReposMap, len(d.repoListEntry))
}
Expand All @@ -715,12 +713,6 @@ func (d *indexData) List(ctx context.Context, q query.Q, opts *ListOptions) (rl
switch field {
case RepoListFieldRepos:
l.Repos = append(l.Repos, rle)
case RepoListFieldMinimal:
l.Minimal[rle.Repository.ID] = &MinimalRepoListEntry{
HasSymbols: rle.Repository.HasSymbols,
Branches: rle.Repository.Branches,
IndexTimeUnix: rle.IndexMetadata.IndexTime.Unix(),
}
case RepoListFieldReposMap:
l.ReposMap[rle.Repository.ID] = MinimalRepoListEntry{
HasSymbols: rle.Repository.HasSymbols,
Expand All @@ -733,7 +725,7 @@ func (d *indexData) List(ctx context.Context, q query.Q, opts *ListOptions) (rl

// Only one of these fields is populated and in all cases the size of that
// field is the number of Repos in this shard.
l.Stats.Repos = len(l.Repos) + len(l.Minimal) + len(l.ReposMap)
l.Stats.Repos = len(l.Repos) + len(l.ReposMap)

return &l, nil
}
Expand Down
Loading

0 comments on commit 80aef13

Please sign in to comment.