Skip to content

Commit 89b8156

Browse files
committed
Add different key prefix for refs and commits
1 parent 2aa90de commit 89b8156

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

models/repo.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,14 @@ func (repo *Repository) APIFormat(mode AccessMode) *api.Repository {
259259
}
260260

261261
// GetCommitsCountCacheKey returns cache key used for commits count caching.
262-
func (repo *Repository) GetCommitsCountCacheKey(contextName string) string {
263-
return fmt.Sprintf("commits-count-%d-%s", repo.ID, contextName)
262+
func (repo *Repository) GetCommitsCountCacheKey(contextName string, isRef bool) string {
263+
var prefix string
264+
if isRef {
265+
prefix = "ref"
266+
} else {
267+
prefix = "commit"
268+
}
269+
return fmt.Sprintf("commits-count-%d-%s-%s", repo.ID, prefix, contextName)
264270
}
265271

266272
func (repo *Repository) innerAPIFormat(mode AccessMode, isParent bool) *api.Repository {

models/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func pushUpdate(opts PushUpdateOptions) (repo *Repository, err error) {
213213
}
214214
} else {
215215
// Clear cache for tag commit count
216-
cache.Remove(repo.GetCommitsCountCacheKey(tagName))
216+
cache.Remove(repo.GetCommitsCountCacheKey(tagName, true))
217217
err = pushUpdateAddTag(repo, gitRepo, tagName)
218218
if err != nil {
219219
return nil, fmt.Errorf("pushUpdateAddTag: %v", err)
@@ -223,7 +223,7 @@ func pushUpdate(opts PushUpdateOptions) (repo *Repository, err error) {
223223
// If is branch reference
224224

225225
// Clear cache for branch commit count
226-
cache.Remove(repo.GetCommitsCountCacheKey(opts.RefFullName[len(git.BranchPrefix):]))
226+
cache.Remove(repo.GetCommitsCountCacheKey(opts.RefFullName[len(git.BranchPrefix):], true))
227227

228228
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
229229
if err != nil {

modules/context/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (r *Repository) GetCommitsCount() (int64, error) {
112112
} else {
113113
contextName = r.CommitID
114114
}
115-
return cache.GetInt64(r.Repository.GetCommitsCountCacheKey(contextName), func() (int64, error) {
115+
return cache.GetInt64(r.Repository.GetCommitsCountCacheKey(contextName, r.IsViewBranch || r.IsViewTag), func() (int64, error) {
116116
return r.Commit.CommitsCount()
117117
})
118118
}

0 commit comments

Comments
 (0)