mirror of
https://github.com/taigrr/gico.git
synced 2026-04-01 18:58:59 -07:00
atart work on caching repos
This commit is contained in:
@@ -14,10 +14,32 @@ import (
|
||||
var (
|
||||
mapTex sync.RWMutex
|
||||
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() {
|
||||
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 {
|
||||
|
||||
@@ -7,12 +7,15 @@ import (
|
||||
type (
|
||||
Month string
|
||||
Commit struct {
|
||||
LOC int `json:"loc,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
TimeStamp time.Time `json:"ts,omitempty"`
|
||||
Author string `json:"author,omitempty"`
|
||||
Repo string `json:"repo,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Deleted int `json:"deleted,omitempty"`
|
||||
Added int `json:"added,omitempty"`
|
||||
FilesChanged int `json:"files_changed,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Hash string `json:"hash,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
|
||||
Freq []int
|
||||
|
||||
Reference in New Issue
Block a user