Skip to content

Use tag's database num commits instead of read the commit counts from git data #34191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions models/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ func UpdateRelease(ctx context.Context, rel *Release) error {
return err
}

func UpdateReleaseNumCommits(ctx context.Context, rel *Release) error {
_, err := db.GetEngine(ctx).ID(rel.ID).Cols("num_commits").Update(rel)
return err
}

// AddReleaseAttachments adds a release attachments
func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs []string) (err error) {
// Check attachments
Expand Down
37 changes: 30 additions & 7 deletions services/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,17 +920,40 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
ctx.Data["RefFullName"] = ctx.Repo.RefFullName
ctx.Data["RefTypeNameSubURL"] = ctx.Repo.RefTypeNameSubURL()
ctx.Data["TreePath"] = ctx.Repo.TreePath

ctx.Data["BranchName"] = ctx.Repo.BranchName

ctx.Data["CommitID"] = ctx.Repo.CommitID

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
}
// for mirror tags, the number of commist may not be set
if rel.NumCommits <= 0 {
rel.NumCommits, err = ctx.Repo.GetCommitsCount()
if err != nil {
ctx.ServerError("GetCommitsCount", err)
return
}
if err := repo_model.UpdateReleaseNumCommits(ctx, rel); err != nil {
ctx.ServerError("UpdateReleaseNumCommits", 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())
Expand Down
Loading