forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

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.

Changed files
+3 -2
knotserver
git
+3 -2
knotserver/git/git.go
··· 300 } 301 302 func (g *GitRepo) LastCommitForPath(path string) (*object.Commit, error) { 303 cacheMu.RLock() 304 - if commit, found := commitCache.Get(path); found { 305 cacheMu.RUnlock() 306 return commit.(*object.Commit), nil 307 } ··· 330 } 331 332 cacheMu.Lock() 333 - commitCache.Set(path, commit, 1) 334 cacheMu.Unlock() 335 336 return commit, nil
··· 300 } 301 302 func (g *GitRepo) LastCommitForPath(path string) (*object.Commit, error) { 303 + cacheKey := fmt.Sprintf("%s:%s", g.h.String(), path) 304 cacheMu.RLock() 305 + if commit, found := commitCache.Get(cacheKey); found { 306 cacheMu.RUnlock() 307 return commit.(*object.Commit), nil 308 } ··· 331 } 332 333 cacheMu.Lock() 334 + commitCache.Set(cacheKey, commit, 1) 335 cacheMu.Unlock() 336 337 return commit, nil