aboutsummaryrefslogtreecommitdiffstats
path: root/modules/cache
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2020-07-06 01:40:34 +0300
committerGitHub <noreply@github.com>2020-07-06 01:40:34 +0300
commit4384320db9afaf22ca493b794a0ef6ed730e2718 (patch)
treeda41c2a9db960d00d783015ac2b4224750de5d88 /modules/cache
parent217647f33170d469ed392e3284cc1149047c1b74 (diff)
downloadgitea-4384320db9afaf22ca493b794a0ef6ed730e2718.tar.gz
gitea-4384320db9afaf22ca493b794a0ef6ed730e2718.zip
Use hash of repo path, ref and entrypath as cache key (#12151)
Diffstat (limited to 'modules/cache')
-rw-r--r--modules/cache/last_commit.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/modules/cache/last_commit.go b/modules/cache/last_commit.go
index 4f17cd8fa5..660a9250d6 100644
--- a/modules/cache/last_commit.go
+++ b/modules/cache/last_commit.go
@@ -5,6 +5,7 @@
package cache
import (
+ "crypto/sha256"
"fmt"
"code.gitea.io/gitea/modules/git"
@@ -34,9 +35,14 @@ func NewLastCommitCache(repoPath string, gitRepo *git.Repository, ttl int64) *La
}
}
+func (c LastCommitCache) getCacheKey(repoPath, ref, entryPath string) string {
+ hashBytes := sha256.Sum256([]byte(fmt.Sprintf("%s:%s:%s", repoPath, ref, entryPath)))
+ return fmt.Sprintf("last_commit:%x", hashBytes)
+}
+
// Get get the last commit information by commit id and entry path
func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) {
- v := c.Cache.Get(fmt.Sprintf("last_commit:%s:%s:%s", c.repoPath, ref, entryPath))
+ v := c.Cache.Get(c.getCacheKey(c.repoPath, ref, entryPath))
if vs, ok := v.(string); ok {
log.Trace("LastCommitCache hit level 1: [%s:%s:%s]", ref, entryPath, vs)
if commit, ok := c.commitCache[vs]; ok {
@@ -60,5 +66,5 @@ func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) {
// Put put the last commit id with commit and entry path
func (c LastCommitCache) Put(ref, entryPath, commitID string) error {
log.Trace("LastCommitCache save: [%s:%s:%s]", ref, entryPath, commitID)
- return c.Cache.Put(fmt.Sprintf("last_commit:%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl)
+ return c.Cache.Put(c.getCacheKey(c.repoPath, ref, entryPath), commitID, c.ttl)
}