Skip to content

Commit a0eaeb5

Browse files
committed
Use pointer of ListOptions instead of struct
1 parent 7b64df5 commit a0eaeb5

File tree

12 files changed

+56
-62
lines changed

12 files changed

+56
-62
lines changed

models/issues/issue_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
// IssuesOptions represents options of an issue.
2323
type IssuesOptions struct { //nolint
24-
db.ListOptions
24+
*db.ListOptions
2525
RepoIDs []int64 // overwrites RepoCond if the length is not 0
2626
AllPublic bool // include also all public repositories
2727
RepoCond builder.Cond

models/issues/issue_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,16 @@ func TestIssues(t *testing.T) {
155155
}{
156156
{
157157
issues_model.IssuesOptions{
158-
ListOptions: db.ListOptionsAll,
159-
AssigneeID: 1,
160-
SortType: "oldest",
158+
AssigneeID: 1,
159+
SortType: "oldest",
161160
},
162161
[]int64{1, 6},
163162
},
164163
{
165164
issues_model.IssuesOptions{
166165
RepoCond: builder.In("repo_id", 1, 3),
167166
SortType: "oldest",
168-
ListOptions: db.ListOptions{
167+
ListOptions: &db.ListOptions{
169168
Page: 1,
170169
PageSize: 4,
171170
},
@@ -175,7 +174,7 @@ func TestIssues(t *testing.T) {
175174
{
176175
issues_model.IssuesOptions{
177176
LabelIDs: []int64{1},
178-
ListOptions: db.ListOptions{
177+
ListOptions: &db.ListOptions{
179178
Page: 1,
180179
PageSize: 4,
181180
},
@@ -185,7 +184,7 @@ func TestIssues(t *testing.T) {
185184
{
186185
issues_model.IssuesOptions{
187186
LabelIDs: []int64{1, 2},
188-
ListOptions: db.ListOptions{
187+
ListOptions: &db.ListOptions{
189188
Page: 1,
190189
PageSize: 4,
191190
},
@@ -194,7 +193,6 @@ func TestIssues(t *testing.T) {
194193
},
195194
{
196195
issues_model.IssuesOptions{
197-
ListOptions: db.ListOptionsAll,
198196
MilestoneIDs: []int64{1},
199197
},
200198
[]int64{2},
@@ -328,7 +326,7 @@ func TestCorrectIssueStats(t *testing.T) {
328326

329327
// Now we will get all issueID's that match the "Bugs are nasty" query.
330328
issues, err := issues_model.Issues(context.TODO(), &issues_model.IssuesOptions{
331-
ListOptions: db.ListOptions{
329+
ListOptions: &db.ListOptions{
332330
PageSize: issueAmount,
333331
},
334332
RepoIDs: []int64{1},

modules/indexer/internal/paginator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import (
1010
)
1111

1212
// ParsePaginator parses a db.Paginator into a skip and limit
13-
func ParsePaginator(listOptions db.ListOptions, max ...int) (int, int) {
13+
func ParsePaginator(listOptions *db.ListOptions, max ...int) (int, int) {
1414
// Use a very large number to indicate no limit
1515
unlimited := math.MaxInt32
1616
if len(max) > 0 {
1717
// Some indexer engines have a limit on the page size, respect that
1818
unlimited = max[0]
1919
}
2020

21-
if listOptions.IsListAll() {
21+
if listOptions == nil || listOptions.IsListAll() {
2222
// It shouldn't happen. In actual usage scenarios, there should not be requests to search all.
2323
// But if it does happen, respect it and return "unlimited".
2424
// And it's also useful for testing.

modules/indexer/issues/db/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
7979
}
8080

8181
// If pagesize == 0, return total count only. It's a special case for search count.
82-
if options.ListOptions.PageSize == 0 {
82+
if options.ListOptions != nil && options.ListOptions.PageSize == 0 {
8383
total, err := issue_model.CountIssues(ctx, opt, cond)
8484
if err != nil {
8585
return nil, err

modules/indexer/issues/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func SearchIssues(ctx context.Context, opts *SearchOptions) ([]int64, int64, err
308308

309309
// CountIssues counts issues by options. It is a shortcut of SearchIssues(ctx, opts) but only returns the total count.
310310
func CountIssues(ctx context.Context, opts *SearchOptions) (int64, error) {
311-
opts = opts.Copy(func(options *SearchOptions) { options.ListOptions = db_model.ListOptions{PageSize: 0} })
311+
opts = opts.Copy(func(options *SearchOptions) { options.ListOptions = &db_model.ListOptions{PageSize: 0} })
312312

313313
_, total, err := SearchIssues(ctx, opts)
314314
return total, err

modules/indexer/issues/indexer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func searchIssueWithPaginator(t *testing.T) {
397397
}{
398398
{
399399
SearchOptions{
400-
ListOptions: db.ListOptions{
400+
ListOptions: &db.ListOptions{
401401
PageSize: 5,
402402
},
403403
},

modules/indexer/issues/internal/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ type SearchOptions struct {
106106
UpdatedAfterUnix optional.Option[int64]
107107
UpdatedBeforeUnix optional.Option[int64]
108108

109-
db.ListOptions
109+
*db.ListOptions
110110

111111
SortBy SortBy // sort by field
112112
}

0 commit comments

Comments
 (0)