Skip to content

Commit 4cfe05f

Browse files
committed
Use the original field name to reduce changes
1 parent a0eaeb5 commit 4cfe05f

File tree

17 files changed

+68
-68
lines changed

17 files changed

+68
-68
lines changed

models/issues/issue_search.go

Lines changed: 5 additions & 5 deletions
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+
Paginator *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
@@ -100,15 +100,15 @@ func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) {
100100
}
101101

102102
func applyLimit(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
103-
if opts.ListOptions.IsListAll() {
103+
if opts.Paginator == nil || opts.Paginator.IsListAll() {
104104
return sess
105105
}
106106

107107
start := 0
108-
if opts.ListOptions.Page > 0 {
109-
start = (opts.ListOptions.Page - 1) * opts.ListOptions.PageSize
108+
if opts.Paginator.Page > 1 {
109+
start = (opts.Paginator.Page - 1) * opts.Paginator.PageSize
110110
}
111-
sess.Limit(opts.ListOptions.PageSize, start)
111+
sess.Limit(opts.Paginator.PageSize, start)
112112

113113
return sess
114114
}

models/issues/issue_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestIssues(t *testing.T) {
164164
issues_model.IssuesOptions{
165165
RepoCond: builder.In("repo_id", 1, 3),
166166
SortType: "oldest",
167-
ListOptions: &db.ListOptions{
167+
Paginator: &db.ListOptions{
168168
Page: 1,
169169
PageSize: 4,
170170
},
@@ -174,7 +174,7 @@ func TestIssues(t *testing.T) {
174174
{
175175
issues_model.IssuesOptions{
176176
LabelIDs: []int64{1},
177-
ListOptions: &db.ListOptions{
177+
Paginator: &db.ListOptions{
178178
Page: 1,
179179
PageSize: 4,
180180
},
@@ -184,7 +184,7 @@ func TestIssues(t *testing.T) {
184184
{
185185
issues_model.IssuesOptions{
186186
LabelIDs: []int64{1, 2},
187-
ListOptions: &db.ListOptions{
187+
Paginator: &db.ListOptions{
188188
Page: 1,
189189
PageSize: 4,
190190
},
@@ -326,7 +326,7 @@ func TestCorrectIssueStats(t *testing.T) {
326326

327327
// Now we will get all issueID's that match the "Bugs are nasty" query.
328328
issues, err := issues_model.Issues(context.TODO(), &issues_model.IssuesOptions{
329-
ListOptions: &db.ListOptions{
329+
Paginator: &db.ListOptions{
330330
PageSize: issueAmount,
331331
},
332332
RepoIDs: []int64{1},

modules/indexer/internal/paginator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ 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(paginator *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 == nil || listOptions.IsListAll() {
21+
if paginator == nil || paginator.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.
2525
return 0, unlimited
2626
}
2727

28-
if listOptions.PageSize == 0 {
28+
if paginator.PageSize == 0 {
2929
// Do not return any results when searching, it's used to get the total count only.
3030
return 0, 0
3131
}
3232

33-
return listOptions.GetSkipTake()
33+
return paginator.GetSkipTake()
3434
}

modules/indexer/issues/bleve/bleve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
266266
indexerQuery = bleve.NewMatchAllQuery()
267267
}
268268

269-
skip, limit := indexer_internal.ParsePaginator(options.ListOptions)
269+
skip, limit := indexer_internal.ParsePaginator(options.Paginator)
270270
search := bleve.NewSearchRequestOptions(indexerQuery, limit, skip, false)
271271

272272
if options.SortBy == "" {

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 != nil && options.ListOptions.PageSize == 0 {
82+
if options.Paginator != nil && options.Paginator.PageSize == 0 {
8383
total, err := issue_model.CountIssues(ctx, opt, cond)
8484
if err != nil {
8585
return nil, err

modules/indexer/issues/db/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
5050
}
5151

5252
opts := &issue_model.IssuesOptions{
53-
ListOptions: options.ListOptions,
53+
Paginator: options.Paginator,
5454
RepoIDs: options.RepoIDs,
5555
AllPublic: options.AllPublic,
5656
RepoCond: nil,

modules/indexer/issues/dboptions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp
6565
searchOpt.UpdatedBeforeUnix = optional.Some(opts.UpdatedBeforeUnix)
6666
}
6767

68-
searchOpt.ListOptions = opts.ListOptions
68+
searchOpt.Paginator = opts.Paginator
6969

7070
switch opts.SortType {
7171
case "":

modules/indexer/issues/elasticsearch/elasticsearch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
248248
// TODO: make it configurable since it's configurable in elasticsearch
249249
const maxPageSize = 10000
250250

251-
skip, limit := indexer_internal.ParsePaginator(options.ListOptions, maxPageSize)
251+
skip, limit := indexer_internal.ParsePaginator(options.Paginator, maxPageSize)
252252
searchResult, err := b.inner.Client.Search().
253253
Index(b.inner.VersionedIndexName()).
254254
Query(query).

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.Paginator = &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+
Paginator: &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+
Paginator *db.ListOptions
110110

111111
SortBy SortBy // sort by field
112112
}

0 commit comments

Comments
 (0)