diff options
author | Gennady Kovshenin <gennady@kovshenin.com> | 2022-10-06 06:21:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-06 11:21:04 +0800 |
commit | fd2d5f06b087965ee588f8e74853cd2032130efa (patch) | |
tree | 7dba7c7eeedf14e4f0212c2c9fa6315249a5c7b6 /routers/api/v1/repo | |
parent | 8765f139c7a1f3b5aafb83ae9b095e6066d77a50 (diff) | |
download | gitea-fd2d5f06b087965ee588f8e74853cd2032130efa.tar.gz gitea-fd2d5f06b087965ee588f8e74853cd2032130efa.zip |
Add `stat` to `ToCommit` function for speed (#21337)
Calls to ToCommit are very slow due to fetching diffs, analyzing files.
This patch lets us supply `stat` as false to speed fetching a commit
when we don't need the diff.
/v1/repo/commits has a default `stat` set as true now. Set to false to
experience fetching thousands of commits per second instead of 2-5 per
second.
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r-- | routers/api/v1/repo/commits.go | 11 | ||||
-rw-r--r-- | routers/api/v1/repo/notes.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 2 |
3 files changed, 11 insertions, 4 deletions
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index 12c329c203..4e77c3f2f5 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -70,7 +70,7 @@ func getCommit(ctx *context.APIContext, identifier string) { return } - json, err := convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil) + json, err := convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, true) if err != nil { ctx.Error(http.StatusInternalServerError, "toCommit", err) return @@ -104,6 +104,10 @@ func GetAllCommits(ctx *context.APIContext) { // in: query // description: filepath of a file/dir // type: string + // - name: stat + // in: query + // description: include diff stats for every commit (disable for speedup, default 'true') + // type: boolean // - name: page // in: query // description: page number of results to return (1-based) @@ -209,9 +213,12 @@ func GetAllCommits(ctx *context.APIContext) { userCache := make(map[string]*user_model.User) apiCommits := make([]*api.Commit, len(commits)) + + stat := ctx.FormString("stat") == "" || ctx.FormBool("stat") + for i, commit := range commits { // Create json struct - apiCommits[i], err = convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache) + apiCommits[i], err = convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache, stat) 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 67f097a424..ee3133adec 100644 --- a/routers/api/v1/repo/notes.go +++ b/routers/api/v1/repo/notes.go @@ -69,7 +69,7 @@ func getNote(ctx *context.APIContext, identifier string) { return } - cmt, err := convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil) + cmt, err := convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil, 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 2cf30e7c47..f6507dceba 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1306,7 +1306,7 @@ func GetPullRequestCommits(ctx *context.APIContext) { apiCommits := make([]*api.Commit, 0, end-start) for i := start; i < end; i++ { - apiCommit, err := convert.ToCommit(ctx.Repo.Repository, baseGitRepo, commits[i], userCache) + apiCommit, err := convert.ToCommit(ctx.Repo.Repository, baseGitRepo, commits[i], userCache, true) if err != nil { ctx.ServerError("toCommit", err) return |