From eca05b09aa269dda1309ee77ac750e29e71c3fd3 Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Thu, 26 Oct 2017 04:37:33 +0300 Subject: Add commit count caching (#2774) * Add commit count caching * Small refactoring * Add different key prefix for refs and commits * Add configuratuion option to allow to change caching time or disable it --- models/repo.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'models/repo.go') diff --git a/models/repo.go b/models/repo.go index 1b1be62f87..eca71568ee 100644 --- a/models/repo.go +++ b/models/repo.go @@ -258,6 +258,17 @@ func (repo *Repository) APIFormat(mode AccessMode) *api.Repository { return repo.innerAPIFormat(mode, false) } +// GetCommitsCountCacheKey returns cache key used for commits count caching. +func (repo *Repository) GetCommitsCountCacheKey(contextName string, isRef bool) string { + var prefix string + if isRef { + prefix = "ref" + } else { + prefix = "commit" + } + return fmt.Sprintf("commits-count-%d-%s-%s", repo.ID, prefix, contextName) +} + func (repo *Repository) innerAPIFormat(mode AccessMode, isParent bool) *api.Repository { var parent *api.Repository -- cgit v1.2.3