From 5fc39748fd71b10af7289ce5d6d0846eca107241 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Sat, 1 Mar 2025 00:52:23 +0200 Subject: [PATCH] knotserver/git: construct a more unique cache key The previous cache key was just the path, so files that are often common across git repos like '.gitignore' etc. show a cached "last commit" time from another repository. Pretty funny. This uses the current plumbing.Hash.String():path as the key which should theoretically be unique to each repository. --- knotserver/git/git.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/knotserver/git/git.go b/knotserver/git/git.go index 53fad88..e1579d8 100644 --- a/knotserver/git/git.go +++ b/knotserver/git/git.go @@ -300,8 +300,9 @@ func (g *GitRepo) WriteTar(w io.Writer, prefix string) error { } func (g *GitRepo) LastCommitForPath(path string) (*object.Commit, error) { + cacheKey := fmt.Sprintf("%s:%s", g.h.String(), path) cacheMu.RLock() - if commit, found := commitCache.Get(path); found { + if commit, found := commitCache.Get(cacheKey); found { cacheMu.RUnlock() return commit.(*object.Commit), nil } @@ -330,7 +331,7 @@ func (g *GitRepo) LastCommitForPath(path string) (*object.Commit, error) { } cacheMu.Lock() - commitCache.Set(path, commit, 1) + commitCache.Set(cacheKey, commit, 1) cacheMu.Unlock() return commit, nil -- knotmirror 0.0.1