From 6d5a85007ca2f19635332edcb0b980c552a78204 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 13 Apr 2025 15:55:22 -0700 Subject: [PATCH] Use tag's database num commits instead of read the commit counts from git data --- services/context/repo.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/services/context/repo.go b/services/context/repo.go index 6f5c772f5e..5b18e0d14e 100644 --- a/services/context/repo.go +++ b/services/context/repo.go @@ -927,13 +927,27 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) { ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch() // only used by the branch selector dropdown: AllowCreateNewRef - ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount() - if err != nil { - ctx.ServerError("GetCommitsCount", err) - return + // if it's a tag, we just get the commits count from database + if ctx.Repo.RefFullName.IsTag() { + rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, ctx.Repo.RefFullName.TagName()) + if err != nil { + if repo_model.IsErrReleaseNotExist(err) { + ctx.NotFound(err) + return + } + ctx.ServerError("GetRelease", err) + return + } + ctx.Repo.CommitsCount = rel.NumCommits + } else { + ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount() + if err != nil { + ctx.ServerError("GetCommitsCount", err) + return + } + ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount + ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache()) } - ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount - ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache()) } }