prepare for git commit chan aggregation

This commit is contained in:
2023-02-14 22:51:54 -08:00
parent f932d2ce21
commit 5d6ca69a2b
5 changed files with 57 additions and 24 deletions

View File

@@ -12,8 +12,9 @@ import (
)
var (
mapTex sync.RWMutex
hashCache map[int]map[string]map[string]types.ExpFreq
mapTex sync.RWMutex
freqHashCache map[int]map[string]map[string]types.ExpFreq
repoHashCache map[int]map[string]map[string]types.ExpRepo
// 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,
@@ -22,16 +23,10 @@ var (
)
func init() {
hashCache = make(map[int]map[string]map[string]types.ExpFreq)
freqHashCache = make(map[int]map[string]map[string]types.ExpFreq)
repoCache = make(map[string][]types.Commit)
}
func CacheRepo(path string, commits []types.Commit) {
mapTex.Lock()
defer mapTex.Unlock()
repoCache[path] = commits
}
func GetCachedRepo(path string, head string) ([]types.Commit, bool) {
mapTex.RLock()
defer mapTex.RUnlock()
@@ -70,7 +65,7 @@ func GetCachedGraph(year int, authors []string, repoPaths []string) (types.Freq,
r := hashSlice(repoPaths)
mapTex.RLock()
defer mapTex.RUnlock()
if m1, ok := hashCache[year]; !ok {
if m1, ok := freqHashCache[year]; !ok {
return types.Freq{}, false
} else {
if m2, ok := m1[a]; !ok {
@@ -89,22 +84,42 @@ func GetCachedGraph(year int, authors []string, repoPaths []string) (types.Freq,
}
}
func CacheRepo(year int, authors, repoPaths []string, commits []types.Commit) {
a := hashSlice(authors)
r := hashSlice(repoPaths)
mapTex.Lock()
defer mapTex.Unlock()
if _, ok := repoHashCache[year]; !ok {
repoHashCache[year] = make(map[string]map[string]types.ExpRepo)
}
if _, ok := repoHashCache[year][a]; !ok {
repoHashCache[year][a] = make(map[string]types.ExpRepo)
}
repoHashCache[year][a][r] = types.ExpRepo{Commits: commits, Created: time.Now()}
go func() {
time.Sleep(time.Hour * 1)
mapTex.Lock()
defer mapTex.Unlock()
delete(repoHashCache[year][a], r)
}()
}
func CacheGraph(year int, authors, repoPaths []string, freq types.Freq) {
a := hashSlice(authors)
r := hashSlice(repoPaths)
mapTex.Lock()
defer mapTex.Unlock()
if _, ok := hashCache[year]; !ok {
hashCache[year] = make(map[string]map[string]types.ExpFreq)
if _, ok := freqHashCache[year]; !ok {
freqHashCache[year] = make(map[string]map[string]types.ExpFreq)
}
if _, ok := hashCache[year][a]; !ok {
hashCache[year][a] = make(map[string]types.ExpFreq)
if _, ok := freqHashCache[year][a]; !ok {
freqHashCache[year][a] = make(map[string]types.ExpFreq)
}
hashCache[year][a][r] = types.ExpFreq{YearFreq: freq, Created: time.Now()}
freqHashCache[year][a][r] = types.ExpFreq{YearFreq: freq, Created: time.Now()}
go func() {
time.Sleep(time.Hour * 1)
mapTex.Lock()
defer mapTex.Unlock()
delete(hashCache[year][a], r)
delete(freqHashCache[year][a], r)
}()
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/taigrr/gico/types"
)
func (paths RepoSet) GetDayCommits(year int, authors []string) ([]types.Commit, error) {
func (paths RepoSet) GetRepoCommits(year int, authors []string) ([][]types.Commit, error) {
yearLength := 365
if year%4 == 0 {
yearLength++
@@ -53,7 +53,7 @@ func (paths RepoSet) GetDayCommits(year int, authors []string) ([]types.Commit,
close(outChan)
}()
freq := YearFreqFromChan(outChan, year)
// CacheGraph(year, authors, paths, freq)
CacheGraph(year, authors, paths, freq)
return freq, nil
}
@@ -94,6 +94,18 @@ func (paths RepoSet) FrequencyChan(year int, authors []string) (types.Freq, erro
wg.Wait()
close(outChan)
}()
yearLength := 365
if year%4 == 0 {
yearLength++
}
freq := make([][]types.Commit, yearLength)
for commit := range cc {
freq[commit.TimeStamp.YearDay()-1]++
}
return freq
for commit := range outChan {
}
freq := YearFreqFromChan(outChan, year)
CacheGraph(year, authors, paths, freq)
return freq, nil

View File

@@ -107,7 +107,7 @@ func (repo Repo) GetCommitSet() (CommitSet, error) {
return nil
})
cs.Commits = commits
CacheRepo(repo.Path, cs.Commits)
// CacheRepo(repo.Path, cs.Commits)
return cs, nil
}