Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-30 22:06:11 +01:00

Add pagination to commit graph page (#8360)

Fixes #8308
This commit is contained in:
jaqra 2019-10-15 00:38:35 +03:00 committed by zeripath
parent 3083522620
commit 086bfb8b4b
4 changed files with 8 additions and 4 deletions

View file

@ -30,7 +30,7 @@ type GraphItem struct {
type GraphItems []GraphItem type GraphItems []GraphItem
// GetCommitGraph return a list of commit (GraphItems) from all branches // GetCommitGraph return a list of commit (GraphItems) from all branches
func GetCommitGraph(r *git.Repository) (GraphItems, error) { func GetCommitGraph(r *git.Repository, page int) (GraphItems, error) {
var CommitGraph []GraphItem var CommitGraph []GraphItem
@ -43,6 +43,7 @@ func GetCommitGraph(r *git.Repository) (GraphItems, error) {
"-C", "-C",
"-M", "-M",
fmt.Sprintf("-n %d", setting.UI.GraphMaxCommitNum), fmt.Sprintf("-n %d", setting.UI.GraphMaxCommitNum),
fmt.Sprintf("--skip=%d", setting.UI.GraphMaxCommitNum*(page-1)),
"--date=iso", "--date=iso",
fmt.Sprintf("--pretty=format:%s", format), fmt.Sprintf("--pretty=format:%s", format),
) )

View file

@ -19,7 +19,7 @@ func BenchmarkGetCommitGraph(b *testing.B) {
} }
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
graph, err := GetCommitGraph(currentRepo) graph, err := GetCommitGraph(currentRepo, 1)
if err != nil { if err != nil {
b.Error("Could get commit graph") b.Error("Could get commit graph")
} }

View file

@ -91,7 +91,9 @@ func Graph(ctx *context.Context) {
return return
} }
graph, err := models.GetCommitGraph(ctx.Repo.GitRepo) page := ctx.QueryInt("page")
graph, err := models.GetCommitGraph(ctx.Repo.GitRepo, page)
if err != nil { if err != nil {
ctx.ServerError("GetCommitGraph", err) ctx.ServerError("GetCommitGraph", err)
return return
@ -103,8 +105,8 @@ func Graph(ctx *context.Context) {
ctx.Data["CommitCount"] = commitsCount ctx.Data["CommitCount"] = commitsCount
ctx.Data["Branch"] = ctx.Repo.BranchName ctx.Data["Branch"] = ctx.Repo.BranchName
ctx.Data["RequireGitGraph"] = true ctx.Data["RequireGitGraph"] = true
ctx.Data["Page"] = context.NewPagination(int(commitsCount), setting.UI.GraphMaxCommitNum, page, 5)
ctx.HTML(200, tplGraph) ctx.HTML(200, tplGraph)
} }
// SearchCommits render commits filtered by keyword // SearchCommits render commits filtered by keyword

View file

@ -37,4 +37,5 @@
</div> </div>
</div> </div>
</div> </div>
{{template "base/paginate" .}}
{{template "base/footer" .}} {{template "base/footer" .}}