mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-19 16:30:15 +00:00
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.
This commit is contained in:
parent
8765f139c7
commit
fd2d5f06b0
5 changed files with 49 additions and 31 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue