Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3d7fd5f

Browse files
committedDec 22, 2019
use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors
1 parent d0f7898 commit 3d7fd5f

File tree

8 files changed

+18
-12
lines changed

8 files changed

+18
-12
lines changed
 

‎models/list_options.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package models
22

33
import (
4-
"code.gitea.io/gitea/modules/setting"
54
"xorm.io/xorm"
65
)
76

@@ -30,8 +29,8 @@ func (opts ListOptions) setEnginePagination(e Engine) Engine {
3029
}
3130

3231
func (opts ListOptions) setDefaultValues() {
33-
if opts.PageSize <= 0 || opts.PageSize > setting.UI.ExplorePagingNum {
34-
opts.PageSize = setting.UI.ExplorePagingNum
32+
if opts.PageSize <= 0 || opts.PageSize > ItemsPerPage {
33+
opts.PageSize = ItemsPerPage
3534
}
3635
if opts.Page <= 0 {
3736
opts.Page = 1

‎models/org.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func GetOrgUsersByOrgID(opts *FindOrgMembersOpts) ([]*OrgUser, error) {
508508
}
509509

510510
func getOrgUsersByOrgID(e Engine, opts *FindOrgMembersOpts) ([]*OrgUser, error) {
511-
ous := make([]*OrgUser, 0, 10)
511+
var ous []*OrgUser
Has a conversation. Original line has a conversation.
512512
sess := e.Where("org_id=?", opts.OrgID)
513513
if opts.PublicOnly {
514514
sess.And("is_public = ?", true)

‎models/repo_watch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func GetRepoWatchersIDs(repoID int64) ([]int64, error) {
154154

155155
// GetWatchers returns range of users watching given repository.
156156
func (repo *Repository) GetWatchers(opts ListOptions) ([]*User, error) {
157-
users := make([]*User, 0, ItemsPerPage)
157+
var users []*User
158158
sess := x.Where("watch.repo_id=?", repo.ID).
159159
Join("LEFT", "watch", "`user`.id=`watch`.user_id").
160160
And("`watch`.mode<>?", RepoWatchModeDont)

‎models/repo_watch_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestRepository_GetWatchers(t *testing.T) {
5959
assert.NoError(t, PrepareTestDatabase())
6060

6161
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
62-
watchers, err := repo.GetWatchers(ListOptions{Page: 1})
62+
watchers, err := repo.GetWatchers(ListOptions{Page: 1, PageSize: ItemsPerPage})
6363
assert.NoError(t, err)
6464
assert.Len(t, watchers, repo.NumWatches)
6565
for _, watcher := range watchers {

‎models/star.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func isStaring(e Engine, userID, repoID int64) bool {
6565

6666
// GetStargazers returns the users that starred the repo.
6767
func (repo *Repository) GetStargazers(opts ListOptions) ([]*User, error) {
68-
users := make([]*User, 0, ItemsPerPage)
68+
var users []*User
6969
sess := x.Where("star.repo_id = ?", repo.ID).
7070
Join("LEFT", "star", "`user`.id = star.uid")
7171
if opts.Page > 0 {

‎routers/api/v1/repo/commits.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func GetAllCommits(ctx *context.APIContext) {
127127
}
128128

129129
pageSize := ctx.QueryInt("limit")
130-
if pageSize <= 0 {
130+
if pageSize <= 0 || pageSize > git.CommitsRangeSize {
131131
pageSize = git.CommitsRangeSize
132132
}
133133

@@ -163,7 +163,7 @@ func GetAllCommits(ctx *context.APIContext) {
163163
return
164164
}
165165

166-
pageCount := int(math.Ceil(float64(commitsCountTotal) / float64(git.CommitsRangeSize)))
166+
pageCount := int(math.Ceil(float64(commitsCountTotal) / float64(pageSize)))
167167

168168
// Query commits
169169
commits, err := baseCommit.CommitsByRange(page, pageSize)
@@ -190,10 +190,10 @@ func GetAllCommits(ctx *context.APIContext) {
190190
i++
191191
}
192192

193-
ctx.SetLinkHeader(int(commitsCountTotal), git.CommitsRangeSize)
193+
ctx.SetLinkHeader(int(commitsCountTotal), pageSize)
194194

195195
ctx.Header().Set("X-Page", strconv.Itoa(page))
196-
ctx.Header().Set("X-PerPage", strconv.Itoa(git.CommitsRangeSize))
196+
ctx.Header().Set("X-PerPage", strconv.Itoa(pageSize))
197197
ctx.Header().Set("X-Total", strconv.FormatInt(commitsCountTotal, 10))
198198
ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount))
199199
ctx.Header().Set("X-HasMore", strconv.FormatBool(page < pageCount))

‎routers/api/v1/user/user.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func Search(ctx *context.APIContext) {
5454
Keyword: strings.Trim(ctx.Query("q"), " "),
5555
UID: com.StrTo(ctx.Query("uid")).MustInt64(),
5656
Type: models.UserTypeIndividual,
57-
ListOptions: models.ListOptions{PageSize: ctx.QueryInt("page")},
57+
ListOptions: models.ListOptions{Page: 1, PageSize: ctx.QueryInt("limit")},
5858
}
5959

6060
users, _, err := models.SearchUsers(opts)

‎routers/repo/release.go

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ func Releases(ctx *context.Context) {
6969
IncludeTags: true,
7070
}
7171

72+
if opts.ListOptions.Page <= 1 {
73+
opts.ListOptions.Page = 1
74+
}
75+
if opts.ListOptions.PageSize <= 0 {
76+
opts.ListOptions.Page = 10
77+
}
78+
7279
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
7380
if err != nil {
7481
ctx.ServerError("GetReleasesByRepoID", err)

0 commit comments

Comments
 (0)
Please sign in to comment.