atart work on caching repos

This commit is contained in:
2023-02-06 23:03:15 -08:00
parent ee2fa0d24a
commit f5f268dff7
2 changed files with 31 additions and 6 deletions

View File

@@ -14,10 +14,32 @@ import (
var ( var (
mapTex sync.RWMutex mapTex sync.RWMutex
hashCache map[int]map[string]map[string]types.ExpFreq hashCache map[int]map[string]map[string]types.ExpFreq
// the Repo Cache holds a list of all commits from HEAD back to parent
// the key is the repo path
// if the hash of the first commit / HEAD commit doesn't match the current HEAD,
// then it can be discarded and reloaded
repoCache map[string][]types.Commit
) )
func init() { func init() {
hashCache = make(map[int]map[string]map[string]types.ExpFreq) hashCache = make(map[int]map[string]map[string]types.ExpFreq)
repoCache = make(map[string][]types.Commit)
}
func IsRepoCached(path string, head string) bool {
mapTex.RLock()
defer mapTex.RUnlock()
if commits, ok := repoCache[path]; !ok {
return false
} else {
return len(commits) > 0 && commits[0].Hash == head
}
}
func CacheRepo(path string, commits []types.Commit) {
mapTex.Lock()
defer mapTex.Unlock()
repoCache[path] = commits
} }
func hashSlice(in []string) string { func hashSlice(in []string) string {

View File

@@ -7,12 +7,15 @@ import (
type ( type (
Month string Month string
Commit struct { Commit struct {
LOC int `json:"loc,omitempty"` Deleted int `json:"deleted,omitempty"`
Message string `json:"message,omitempty"` Added int `json:"added,omitempty"`
TimeStamp time.Time `json:"ts,omitempty"` FilesChanged int `json:"files_changed,omitempty"`
Author string `json:"author,omitempty"` Message string `json:"message,omitempty"`
Repo string `json:"repo,omitempty"` Hash string `json:"hash,omitempty"`
Path string `json:"path,omitempty"` TimeStamp time.Time `json:"ts,omitempty"`
Author string `json:"author,omitempty"`
Repo string `json:"repo,omitempty"`
Path string `json:"path,omitempty"`
} }
DataSet map[time.Time]WorkDay DataSet map[time.Time]WorkDay
Freq []int Freq []int