diff options
author | jaqra <48099350+jaqra@users.noreply.github.com> | 2019-10-15 00:38:35 +0300 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2019-10-14 22:38:35 +0100 |
commit | 086bfb8b4b655f46ac9471cbea9df70e912c315d (patch) | |
tree | f89c2f17afa05b622e644a81ae09c087d83452b3 | |
parent | 30835226207f9a618bb2d4956fb209b1dbe099e6 (diff) | |
download | gitea-086bfb8b4b655f46ac9471cbea9df70e912c315d.tar.gz gitea-086bfb8b4b655f46ac9471cbea9df70e912c315d.zip |
Add pagination to commit graph page (#8360)
Fixes #8308
-rw-r--r-- | models/graph.go | 3 | ||||
-rw-r--r-- | models/graph_test.go | 2 | ||||
-rw-r--r-- | routers/repo/commit.go | 6 | ||||
-rw-r--r-- | templates/repo/graph.tmpl | 1 |
4 files changed, 8 insertions, 4 deletions
diff --git a/models/graph.go b/models/graph.go index 5f68abaf74..0efb51b3fc 100644 --- a/models/graph.go +++ b/models/graph.go @@ -30,7 +30,7 @@ type GraphItem struct { type GraphItems []GraphItem // 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 @@ -43,6 +43,7 @@ func GetCommitGraph(r *git.Repository) (GraphItems, error) { "-C", "-M", fmt.Sprintf("-n %d", setting.UI.GraphMaxCommitNum), + fmt.Sprintf("--skip=%d", setting.UI.GraphMaxCommitNum*(page-1)), "--date=iso", fmt.Sprintf("--pretty=format:%s", format), ) diff --git a/models/graph_test.go b/models/graph_test.go index 5c78e3877b..c1f0bc90d9 100644 --- a/models/graph_test.go +++ b/models/graph_test.go @@ -19,7 +19,7 @@ func BenchmarkGetCommitGraph(b *testing.B) { } for i := 0; i < b.N; i++ { - graph, err := GetCommitGraph(currentRepo) + graph, err := GetCommitGraph(currentRepo, 1) if err != nil { b.Error("Could get commit graph") } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 3cedf70319..550e4c3a9c 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -91,7 +91,9 @@ func Graph(ctx *context.Context) { return } - graph, err := models.GetCommitGraph(ctx.Repo.GitRepo) + page := ctx.QueryInt("page") + + graph, err := models.GetCommitGraph(ctx.Repo.GitRepo, page) if err != nil { ctx.ServerError("GetCommitGraph", err) return @@ -103,8 +105,8 @@ func Graph(ctx *context.Context) { ctx.Data["CommitCount"] = commitsCount ctx.Data["Branch"] = ctx.Repo.BranchName ctx.Data["RequireGitGraph"] = true + ctx.Data["Page"] = context.NewPagination(int(commitsCount), setting.UI.GraphMaxCommitNum, page, 5) ctx.HTML(200, tplGraph) - } // SearchCommits render commits filtered by keyword diff --git a/templates/repo/graph.tmpl b/templates/repo/graph.tmpl index 2e8d0b5d91..20fe3d1527 100644 --- a/templates/repo/graph.tmpl +++ b/templates/repo/graph.tmpl @@ -37,4 +37,5 @@ </div> </div> </div> +{{template "base/paginate" .}} {{template "base/footer" .}} |