mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
atart work on caching repos
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user