diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-02-05 01:23:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-04 11:23:46 -0600 |
commit | 3537d80088286880cbf4ba24ac2795dead364253 (patch) | |
tree | caf4f4b6211d20a02deaeb287178aff014c5af00 /models | |
parent | 80b1d02b2f631a9e68120715a82f7f41f203ef79 (diff) | |
download | gitea-3537d80088286880cbf4ba24ac2795dead364253.tar.gz gitea-3537d80088286880cbf4ba24ac2795dead364253.zip |
Fix bug about ListOptions and stars/watchers pagnation (#14556)
* Fix bug about ListOptions and stars/watchers pagnation
* fix unit test
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models')
-rw-r--r-- | models/commit_status_test.go | 2 | ||||
-rw-r--r-- | models/list_options.go | 10 |
2 files changed, 6 insertions, 6 deletions
diff --git a/models/commit_status_test.go b/models/commit_status_test.go index 90d72cd74d..57b97f6606 100644 --- a/models/commit_status_test.go +++ b/models/commit_status_test.go @@ -18,7 +18,7 @@ func TestGetCommitStatuses(t *testing.T) { sha1 := "1234123412341234123412341234123412341234" - statuses, maxResults, err := GetCommitStatuses(repo1, sha1, &CommitStatusOptions{}) + statuses, maxResults, err := GetCommitStatuses(repo1, sha1, &CommitStatusOptions{ListOptions: ListOptions{Page: 1, PageSize: 50}}) assert.NoError(t, err) assert.Equal(t, int(maxResults), 5) assert.Len(t, statuses, 5) diff --git a/models/list_options.go b/models/list_options.go index 0912355352..9cccd05465 100644 --- a/models/list_options.go +++ b/models/list_options.go @@ -16,13 +16,13 @@ type ListOptions struct { Page int // start from 1 } -func (opts ListOptions) getPaginatedSession() *xorm.Session { +func (opts *ListOptions) getPaginatedSession() *xorm.Session { opts.setDefaultValues() return x.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) } -func (opts ListOptions) setSessionPagination(sess *xorm.Session) *xorm.Session { +func (opts *ListOptions) setSessionPagination(sess *xorm.Session) *xorm.Session { opts.setDefaultValues() if opts.PageSize <= 0 { @@ -31,21 +31,21 @@ func (opts ListOptions) setSessionPagination(sess *xorm.Session) *xorm.Session { return sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) } -func (opts ListOptions) setEnginePagination(e Engine) Engine { +func (opts *ListOptions) setEnginePagination(e Engine) Engine { opts.setDefaultValues() return e.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) } // GetStartEnd returns the start and end of the ListOptions -func (opts ListOptions) GetStartEnd() (start, end int) { +func (opts *ListOptions) GetStartEnd() (start, end int) { opts.setDefaultValues() start = (opts.Page - 1) * opts.PageSize end = start + opts.Page return } -func (opts ListOptions) setDefaultValues() { +func (opts *ListOptions) setDefaultValues() { if opts.PageSize <= 0 { opts.PageSize = setting.API.DefaultPagingNum } |