mirror of
https://github.com/go-gitea/gitea
synced 2025-08-23 18:08:28 +00:00
API add/generalize pagination (#9452)
* paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
committed by
techknowlogick
parent
333401e0fd
commit
1f01f53c53
@@ -58,8 +58,13 @@ func Commits(ctx *context.Context) {
|
||||
page = 1
|
||||
}
|
||||
|
||||
pageSize := ctx.QueryInt("limit")
|
||||
if pageSize <= 0 {
|
||||
pageSize = git.CommitsRangeSize
|
||||
}
|
||||
|
||||
// Both `git log branchName` and `git log commitId` work.
|
||||
commits, err := ctx.Repo.Commit.CommitsByRange(page)
|
||||
commits, err := ctx.Repo.Commit.CommitsByRange(page, pageSize)
|
||||
if err != nil {
|
||||
ctx.ServerError("CommitsByRange", err)
|
||||
return
|
||||
|
@@ -195,13 +195,15 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB
|
||||
issues = []*models.Issue{}
|
||||
} else {
|
||||
issues, err = models.Issues(&models.IssuesOptions{
|
||||
ListOptions: models.ListOptions{
|
||||
Page: pager.Paginater.Current(),
|
||||
PageSize: setting.UI.IssuePagingNum,
|
||||
},
|
||||
RepoIDs: []int64{repo.ID},
|
||||
AssigneeID: assigneeID,
|
||||
PosterID: posterID,
|
||||
MentionedID: mentionedID,
|
||||
MilestoneID: milestoneID,
|
||||
Page: pager.Paginater.Current(),
|
||||
PageSize: setting.UI.IssuePagingNum,
|
||||
IsClosed: util.OptionalBoolOf(isShowClosed),
|
||||
IsPull: isPullOption,
|
||||
LabelIDs: labelIDs,
|
||||
@@ -246,7 +248,7 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB
|
||||
return
|
||||
}
|
||||
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "")
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByRepoID", err)
|
||||
return
|
||||
@@ -309,7 +311,7 @@ func Issues(ctx *context.Context) {
|
||||
|
||||
var err error
|
||||
// Get milestones.
|
||||
ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")))
|
||||
ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")), models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetAllRepoMilestones", err)
|
||||
return
|
||||
@@ -347,7 +349,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull boo
|
||||
return nil
|
||||
}
|
||||
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "")
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByRepoID", err)
|
||||
return nil
|
||||
@@ -733,7 +735,7 @@ func ViewIssue(ctx *context.Context) {
|
||||
for i := range issue.Labels {
|
||||
labelIDMark[issue.Labels[i].ID] = true
|
||||
}
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "")
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByRepoID", err)
|
||||
return
|
||||
|
@@ -50,7 +50,7 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
|
||||
|
||||
// RetrieveLabels find all the labels of a repository
|
||||
func RetrieveLabels(ctx *context.Context) {
|
||||
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"))
|
||||
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"), models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("RetrieveLabels.GetLabels", err)
|
||||
return
|
||||
|
@@ -12,6 +12,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -56,24 +57,26 @@ func Releases(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
|
||||
ctx.Data["PageIsReleaseList"] = true
|
||||
|
||||
page := ctx.QueryInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
limit := ctx.QueryInt("limit")
|
||||
if limit <= 0 {
|
||||
limit = 10
|
||||
}
|
||||
|
||||
writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases)
|
||||
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived
|
||||
|
||||
opts := models.FindReleasesOptions{
|
||||
ListOptions: models.ListOptions{
|
||||
Page: ctx.QueryInt("page"),
|
||||
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
|
||||
},
|
||||
IncludeDrafts: writeAccess,
|
||||
IncludeTags: true,
|
||||
}
|
||||
|
||||
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts, page, limit)
|
||||
if opts.ListOptions.Page <= 1 {
|
||||
opts.ListOptions.Page = 1
|
||||
}
|
||||
if opts.ListOptions.PageSize <= 0 {
|
||||
opts.ListOptions.Page = 10
|
||||
}
|
||||
|
||||
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetReleasesByRepoID", err)
|
||||
return
|
||||
@@ -121,7 +124,7 @@ func Releases(ctx *context.Context) {
|
||||
|
||||
ctx.Data["Releases"] = releases
|
||||
|
||||
pager := context.NewPagination(int(count), limit, page, 5)
|
||||
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
|
@@ -486,7 +486,7 @@ func Collaboration(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings")
|
||||
ctx.Data["PageIsSettingsCollaboration"] = true
|
||||
|
||||
users, err := ctx.Repo.Repository.GetCollaborators()
|
||||
users, err := ctx.Repo.Repository.GetCollaborators(models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetCollaborators", err)
|
||||
return
|
||||
@@ -738,7 +738,7 @@ func DeployKeys(ctx *context.Context) {
|
||||
ctx.Data["PageIsSettingsKeys"] = true
|
||||
ctx.Data["DisableSSH"] = setting.SSH.Disabled
|
||||
|
||||
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
|
||||
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID, models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("ListDeployKeys", err)
|
||||
return
|
||||
@@ -753,7 +753,7 @@ func DeployKeysPost(ctx *context.Context, form auth.AddKeyForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
|
||||
ctx.Data["PageIsSettingsKeys"] = true
|
||||
|
||||
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
|
||||
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID, models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("ListDeployKeys", err)
|
||||
return
|
||||
|
@@ -522,7 +522,7 @@ func renderCode(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// RenderUserCards render a page show users according the input templaet
|
||||
func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*models.User, error), tpl base.TplName) {
|
||||
func RenderUserCards(ctx *context.Context, total int, getter func(opts models.ListOptions) ([]*models.User, error), tpl base.TplName) {
|
||||
page := ctx.QueryInt("page")
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
@@ -530,7 +530,7 @@ func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*
|
||||
pager := context.NewPagination(total, models.ItemsPerPage, page, 5)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
items, err := getter(pager.Paginater.Current())
|
||||
items, err := getter(models.ListOptions{Page: pager.Paginater.Current()})
|
||||
if err != nil {
|
||||
ctx.ServerError("getter", err)
|
||||
return
|
||||
@@ -561,7 +561,7 @@ func Stars(ctx *context.Context) {
|
||||
func Forks(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repos.forks")
|
||||
|
||||
forks, err := ctx.Repo.Repository.GetForks()
|
||||
forks, err := ctx.Repo.Repository.GetForks(models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetForks", err)
|
||||
return
|
||||
|
@@ -38,7 +38,7 @@ func Webhooks(ctx *context.Context) {
|
||||
ctx.Data["BaseLink"] = ctx.Repo.RepoLink + "/settings/hooks"
|
||||
ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://docs.gitea.io/en-us/webhooks/")
|
||||
|
||||
ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
|
||||
ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID, models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetWebhooksByRepoID", err)
|
||||
return
|
||||
|
Reference in New Issue
Block a user