loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make branches list page operations remember current page (#23420)

Close #23411

Always pass "page" query parameter to backend, and make backend respect
it.

The `ctx.FormInt("limit")` is never used, so removed.

---------

Co-authored-by: Jason Song <i@wolfogre.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>

authored by

wxiaoguang
Jason Song
Lunny Xiao
and committed by
GitHub
6ff5400a 0efa9d56

+15 -17
+4 -3
modules/context/pagination.go
··· 18 18 urlParams []string 19 19 } 20 20 21 - // NewPagination creates a new instance of the Pagination struct 22 - func NewPagination(total, page, issueNum, numPages int) *Pagination { 21 + // NewPagination creates a new instance of the Pagination struct. 22 + // "pagingNum" is "page size" or "limit", "current" is "page" 23 + func NewPagination(total, pagingNum, current, numPages int) *Pagination { 23 24 p := &Pagination{} 24 - p.Paginater = paginator.New(total, page, issueNum, numPages) 25 + p.Paginater = paginator.New(total, pagingNum, current, numPages) 25 26 return p 26 27 } 27 28
+7 -10
routers/web/repo/branch.go
··· 8 8 "errors" 9 9 "fmt" 10 10 "net/http" 11 + "net/url" 11 12 "strings" 12 13 13 14 "code.gitea.io/gitea/models" ··· 65 66 if page <= 1 { 66 67 page = 1 67 68 } 69 + pageSize := setting.Git.BranchesRangeSize 68 70 69 - limit := ctx.FormInt("limit") 70 - if limit <= 0 || limit > setting.Git.BranchesRangeSize { 71 - limit = setting.Git.BranchesRangeSize 72 - } 73 - 74 - skip := (page - 1) * limit 75 - log.Debug("Branches: skip: %d limit: %d", skip, limit) 76 - defaultBranchBranch, branches, branchesCount := loadBranches(ctx, skip, limit) 71 + skip := (page - 1) * pageSize 72 + log.Debug("Branches: skip: %d limit: %d", skip, pageSize) 73 + defaultBranchBranch, branches, branchesCount := loadBranches(ctx, skip, pageSize) 77 74 if ctx.Written() { 78 75 return 79 76 } 80 77 ctx.Data["Branches"] = branches 81 78 ctx.Data["DefaultBranchBranch"] = defaultBranchBranch 82 - pager := context.NewPagination(branchesCount, setting.Git.BranchesRangeSize, page, 5) 79 + pager := context.NewPagination(branchesCount, pageSize, page, 5) 83 80 pager.SetDefaultParams(ctx) 84 81 ctx.Data["Page"] = pager 85 82 ··· 165 162 166 163 func redirect(ctx *context.Context) { 167 164 ctx.JSON(http.StatusOK, map[string]interface{}{ 168 - "redirect": ctx.Repo.RepoLink + "/branches", 165 + "redirect": ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")), 169 166 }) 170 167 } 171 168
+4 -4
templates/repo/branch/list.tmpl
··· 81 81 <td class="three wide right aligned"> 82 82 {{if not .LatestPullRequest}} 83 83 {{if .IsIncluded}} 84 - <a class="ui tooltip orange large label" data-content="{{$.locale.Tr "repo.branch.included_desc"}}" data-position="top right"> 84 + <span class="ui tooltip orange large label" data-content="{{$.locale.Tr "repo.branch.included_desc"}}" data-position="top right"> 85 85 {{svg "octicon-git-pull-request"}} {{$.locale.Tr "repo.branch.included"}} 86 - </a> 86 + </span> 87 87 {{else if and (not .IsDeleted) $.AllowsPulls (gt .CommitsAhead 0)}} 88 88 <a href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.DefaultBranch}}...{{if ne $.Repository.Owner.Name $.Owner.Name}}{{PathEscape $.Owner.Name}}:{{end}}{{PathEscapeSegments .Name}}"> 89 89 <button id="new-pull-request" class="ui compact basic button gt-mr-0">{{if $.CanPull}}{{$.locale.Tr "repo.pulls.compare_changes"}}{{else}}{{$.locale.Tr "action.compare_branch"}}{{end}}</button> ··· 123 123 {{end}} 124 124 {{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}} 125 125 {{if .IsDeleted}} 126 - <button class="ui basic jump button icon tooltip undo-button" data-url="{{$.Link}}/restore?branch_id={{.DeletedBranch.ID}}&name={{.DeletedBranch.Name}}" data-content="{{$.locale.Tr "repo.branch.restore" (.Name)}}" data-position="top right"> 126 + <button class="ui basic jump button icon tooltip undo-button" data-url="{{$.Link}}/restore?branch_id={{.DeletedBranch.ID}}&name={{.DeletedBranch.Name}}&page={{$.Page.Paginater.Current}}" data-content="{{$.locale.Tr "repo.branch.restore" (.Name)}}" data-position="top right"> 127 127 <span class="text blue"> 128 128 {{svg "octicon-reply"}} 129 129 </span> 130 130 </button> 131 131 {{else}} 132 - <button class="ui basic jump button icon tooltip delete-button delete-branch-button" data-url="{{$.Link}}/delete?name={{.Name}}" data-content="{{$.locale.Tr "repo.branch.delete" (.Name)}}" data-position="top right" data-name="{{.Name}}"> 132 + <button class="ui basic jump button icon tooltip delete-button delete-branch-button" data-url="{{$.Link}}/delete?name={{.Name}}&page={{$.Page.Paginater.Current}}" data-content="{{$.locale.Tr "repo.branch.delete" (.Name)}}" data-position="top right" data-name="{{.Name}}"> 133 133 {{svg "octicon-trash"}} 134 134 </button> 135 135 {{end}}