diff options
author | Giteabot <teabot@gitea.io> | 2024-07-20 01:12:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-19 13:12:23 -0400 |
commit | 00aade2cab71f9a0c3a590cb5557f842fb7dba26 (patch) | |
tree | fb70768ab95946595b03117f3015ac2eb4ecaafe | |
parent | c2b1b94c5a28deab2c65cae3e84124a14f6cbb20 (diff) | |
download | gitea-00aade2cab71f9a0c3a590cb5557f842fb7dba26.tar.gz gitea-00aade2cab71f9a0c3a590cb5557f842fb7dba26.zip |
Fix a branch divergence cache bug (#31659) (#31661)
Backport #31659 by @Zettat123
Fix #31599
Fix #31472
A branch divergence is counted based on the default branch. If the
default branch is updated, all divergence caches of the repo need to be
deleted.
Co-authored-by: Zettat123 <zettat123@gmail.com>
-rw-r--r-- | services/repository/branch.go | 17 | ||||
-rw-r--r-- | services/repository/push.go | 10 |
2 files changed, 25 insertions, 2 deletions
diff --git a/services/repository/branch.go b/services/repository/branch.go index bc97f3f632..0afd0cd76a 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -147,6 +147,23 @@ func DelDivergenceFromCache(repoID int64, branchName string) error { return cache.GetCache().Delete(getDivergenceCacheKey(repoID, branchName)) } +// DelRepoDivergenceFromCache deletes all divergence caches of a repository +func DelRepoDivergenceFromCache(ctx context.Context, repoID int64) error { + dbBranches, err := db.Find[git_model.Branch](ctx, git_model.FindBranchOptions{ + RepoID: repoID, + ListOptions: db.ListOptionsAll, + }) + if err != nil { + return err + } + for i := range dbBranches { + if err := DelDivergenceFromCache(repoID, dbBranches[i].Name); err != nil { + log.Error("DelDivergenceFromCache: %v", err) + } + } + return nil +} + func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *git_model.Branch, protectedBranches *git_model.ProtectedBranchRules, repoIDToRepo map[int64]*repo_model.Repository, repoIDToGitRepo map[int64]*git.Repository, diff --git a/services/repository/push.go b/services/repository/push.go index 39843249a5..f27e6a58dd 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -221,8 +221,14 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } // delete cache for divergence - if err := DelDivergenceFromCache(repo.ID, branch); err != nil { - log.Error("DelDivergenceFromCache: %v", err) + if branch == repo.DefaultBranch { + if err := DelRepoDivergenceFromCache(ctx, repo.ID); err != nil { + log.Error("DelRepoDivergenceFromCache: %v", err) + } + } else { + if err := DelDivergenceFromCache(repo.ID, branch); err != nil { + log.Error("DelDivergenceFromCache: %v", err) + } } commits := repo_module.GitToPushCommits(l) |