Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: remove deprecated RepoList.Minimal #624

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,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 @@ -842,16 +837,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 @@ -860,13 +849,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 @@ -620,18 +620,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 @@ -646,17 +639,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: repos,
ReposMap: reposMap,
Crashes: int64(r.Crashes),
Stats: r.Stats.ToProto(),
Minimal: minimal,
}
}

Expand All @@ -668,15 +655,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 @@ -688,14 +672,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 @@ -394,12 +394,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
10 changes: 1 addition & 9 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,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 @@ -720,12 +718,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 @@ -738,7 +730,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
Loading