From 52324ade6047530d5b30d134c8b82b469a5eea3c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 4 Feb 2021 00:18:29 +0800 Subject: [PATCH 1/2] Fix bug about ListOptions and stars/watchers pagnation --- models/list_options.go | 10 +++++----- routers/repo/view.go | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/models/list_options.go b/models/list_options.go index 0912355352d69..9cccd05465afe 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 } diff --git a/routers/repo/view.go b/routers/repo/view.go index 25d40c34d8f2b..45f17dee44b96 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -713,7 +713,10 @@ func RenderUserCards(ctx *context.Context, total int, getter func(opts models.Li pager := context.NewPagination(total, models.ItemsPerPage, page, 5) ctx.Data["Page"] = pager - items, err := getter(models.ListOptions{Page: pager.Paginater.Current()}) + items, err := getter(models.ListOptions{ + Page: pager.Paginater.Current(), + PageSize: models.ItemsPerPage, + }) if err != nil { ctx.ServerError("getter", err) return @@ -744,6 +747,7 @@ func Stars(ctx *context.Context) { func Forks(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repos.forks") + // TODO: need pagination forks, err := ctx.Repo.Repository.GetForks(models.ListOptions{}) if err != nil { ctx.ServerError("GetForks", err) From 6f5b578545c36d92059d6301c56e3f22fb9ebbef Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 4 Feb 2021 02:06:31 +0100 Subject: [PATCH 2/2] fix unit test --- models/commit_status_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/commit_status_test.go b/models/commit_status_test.go index 90d72cd74dfb2..57b97f66063ef 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)