summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorMatthew Walowski <mattwalowski@gmail.com>2023-05-08 18:06:05 -0700
committerGitHub <noreply@github.com>2023-05-09 09:06:05 +0800
commit1dd83dbb917d55bd253001646d6743f247a4d98b (patch)
tree8c0a0f9e6903e366a7ed8ee043f686ecd40f343a /routers
parent707c7e60c94c5b0d27ade7462dda1e526d35f369 (diff)
downloadgitea-1dd83dbb917d55bd253001646d6743f247a4d98b.tar.gz
gitea-1dd83dbb917d55bd253001646d6743f247a4d98b.zip
Filters for GetAllCommits (#24568)
The `GetAllCommits` endpoint can be pretty slow, especially in repos with a lot of commits. The issue is that it spends a lot of time calculating information that may not be useful/needed by the user. The `stat` param was previously added in #21337 to address this, by allowing the user to disable the calculating stats for each commit. But this has two issues: 1. The name `stat` is rather misleading, because disabling `stat` disables the Stat **and** Files. This should be separated out into two different params, because getting a list of affected files is much less expensive than calculating the stats 2. There's still other costly information provided that the user may not need, such as `Verification` This PR, adds two parameters to the endpoint, `files` and `verification` to allow the user to explicitly disable this information when listing commits. The default behavior is true.
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/commits.go20
-rw-r--r--routers/api/v1/repo/notes.go2
-rw-r--r--routers/api/v1/repo/pull.go2
3 files changed, 20 insertions, 4 deletions
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go
index a5e2e7baef..9b7de91a72 100644
--- a/routers/api/v1/repo/commits.go
+++ b/routers/api/v1/repo/commits.go
@@ -69,7 +69,7 @@ func getCommit(ctx *context.APIContext, identifier string) {
return
}
- json, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, true)
+ json, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, convert.ToCommitOptions{Stat: true})
if err != nil {
ctx.Error(http.StatusInternalServerError, "toCommit", err)
return
@@ -107,6 +107,14 @@ func GetAllCommits(ctx *context.APIContext) {
// in: query
// description: include diff stats for every commit (disable for speedup, default 'true')
// type: boolean
+ // - name: verification
+ // in: query
+ // description: include verification for every commit (disable for speedup, default 'true')
+ // type: boolean
+ // - name: files
+ // in: query
+ // description: include a list of affected files for every commit (disable for speedup, default 'true')
+ // type: boolean
// - name: page
// in: query
// description: page number of results to return (1-based)
@@ -238,10 +246,18 @@ func GetAllCommits(ctx *context.APIContext) {
apiCommits := make([]*api.Commit, len(commits))
stat := ctx.FormString("stat") == "" || ctx.FormBool("stat")
+ verification := ctx.FormString("verification") == "" || ctx.FormBool("verification")
+ files := ctx.FormString("files") == "" || ctx.FormBool("files")
for i, commit := range commits {
// Create json struct
- apiCommits[i], err = convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache, stat)
+ apiCommits[i], err = convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache,
+ convert.ToCommitOptions{
+ Stat: stat,
+ Verification: verification,
+ Files: files,
+ })
+
if err != nil {
ctx.Error(http.StatusInternalServerError, "toCommit", err)
return
diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go
index 74969f2cad..1bd66101f0 100644
--- a/routers/api/v1/repo/notes.go
+++ b/routers/api/v1/repo/notes.go
@@ -78,7 +78,7 @@ func getNote(ctx *context.APIContext, identifier string) {
return
}
- cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil, true)
+ cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil, convert.ToCommitOptions{Stat: true})
if err != nil {
ctx.Error(http.StatusInternalServerError, "ToCommit", err)
return
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index f4e2969d7d..a507c1f44d 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -1318,7 +1318,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
apiCommits := make([]*api.Commit, 0, end-start)
for i := start; i < end; i++ {
- apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, true)
+ apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache, convert.ToCommitOptions{Stat: true})
if err != nil {
ctx.ServerError("toCommit", err)
return