Skip to content

Commit 6d5a850

Browse files
committed
Use tag's database num commits instead of read the commit counts from git data
1 parent bec9233 commit 6d5a850

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

services/context/repo.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -927,13 +927,27 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
927927

928928
ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch() // only used by the branch selector dropdown: AllowCreateNewRef
929929

930-
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
931-
if err != nil {
932-
ctx.ServerError("GetCommitsCount", err)
933-
return
930+
// if it's a tag, we just get the commits count from database
931+
if ctx.Repo.RefFullName.IsTag() {
932+
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, ctx.Repo.RefFullName.TagName())
933+
if err != nil {
934+
if repo_model.IsErrReleaseNotExist(err) {
935+
ctx.NotFound(err)
936+
return
937+
}
938+
ctx.ServerError("GetRelease", err)
939+
return
940+
}
941+
ctx.Repo.CommitsCount = rel.NumCommits
942+
} else {
943+
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
944+
if err != nil {
945+
ctx.ServerError("GetCommitsCount", err)
946+
return
947+
}
948+
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
949+
ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache())
934950
}
935-
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
936-
ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache())
937951
}
938952
}
939953

0 commit comments

Comments
 (0)