forked from Shiloh/githaven
Fix a branch divergence cache bug (#31659)
Fix #31599 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.
This commit is contained in:
parent
03c8c2683c
commit
e9aa39bda4
@ -147,6 +147,23 @@ func DelDivergenceFromCache(repoID int64, branchName string) error {
|
|||||||
return cache.GetCache().Delete(getDivergenceCacheKey(repoID, branchName))
|
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,
|
func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *git_model.Branch, protectedBranches *git_model.ProtectedBranchRules,
|
||||||
repoIDToRepo map[int64]*repo_model.Repository,
|
repoIDToRepo map[int64]*repo_model.Repository,
|
||||||
repoIDToGitRepo map[int64]*git.Repository,
|
repoIDToGitRepo map[int64]*git.Repository,
|
||||||
|
@ -221,9 +221,15 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// delete cache for divergence
|
// delete cache for divergence
|
||||||
|
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 {
|
if err := DelDivergenceFromCache(repo.ID, branch); err != nil {
|
||||||
log.Error("DelDivergenceFromCache: %v", err)
|
log.Error("DelDivergenceFromCache: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
commits := repo_module.GitToPushCommits(l)
|
commits := repo_module.GitToPushCommits(l)
|
||||||
commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
|
commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
|
||||||
|
Loading…
Reference in New Issue
Block a user