2
0

Performance optimization for tags synchronization (#34355)

The tags synchronization is very slow for a non-mirror repository with
many tags especially forking. This PR make all repositories' tags
synchronization use the same function and remove the low performance
synchronization function. The commit count of tag now will not be stored
into database when syncing. Since the commits count will always be read
from cache or git data, the `NumCommits` in the release table will be
updated for the first read from git data.
This commit is contained in:
Lunny Xiao
2025-05-22 13:54:42 -07:00
committed by GitHub
parent c826ed20a2
commit 36bbc3eec7
7 changed files with 31 additions and 190 deletions

View File

@@ -936,6 +936,15 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
ctx.ServerError("GetCommitsCount", err)
return
}
if ctx.Repo.RefFullName.IsTag() {
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, ctx.Repo.RefFullName.TagName())
if err == nil && rel.NumCommits <= 0 {
rel.NumCommits = ctx.Repo.CommitsCount
if err := repo_model.UpdateReleaseNumCommits(ctx, rel); err != nil {
log.Error("UpdateReleaseNumCommits", err)
}
}
}
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache())
}