mirror of
https://github.com/taigrr/gico.git
synced 2026-04-01 18:58:59 -07:00
prepare for git commit chan aggregation
This commit is contained in:
@@ -29,7 +29,7 @@ type model struct {
|
||||
type CommitLog struct {
|
||||
Year int
|
||||
YearDay int
|
||||
Commits []types.Commit
|
||||
Commits [][]types.Commit
|
||||
Selected int
|
||||
Authors []string
|
||||
Repos []string
|
||||
@@ -70,7 +70,7 @@ func initialModel() (model, error) {
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
m.CommitLogModel, err := NewCommitLog()
|
||||
m.CommitLogModel, err = NewCommitLog()
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
@@ -172,6 +172,7 @@ func (m Graph) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func NewCommitLog() (CommitLog, error) {
|
||||
var m CommitLog
|
||||
now := time.Now()
|
||||
@@ -188,8 +189,8 @@ func NewCommitLog() (CommitLog, error) {
|
||||
m.Authors = authors
|
||||
m.Year = year
|
||||
m.Selected = today
|
||||
m.Commits = mr.GetDayCommits(m.Year, m.Selected, m.Authors)
|
||||
return m, nil
|
||||
m.Commits, err = mr.GetRepoCommits(m.Year, m.Authors)
|
||||
return m, err
|
||||
}
|
||||
|
||||
func NewGraph() (Graph, error) {
|
||||
@@ -249,7 +250,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
default:
|
||||
}
|
||||
switch m.cursor {
|
||||
// multiple cursors defined for extensibility, but only graph is used
|
||||
// multiple cursors defined for extensibility, but only graph is used
|
||||
case graph, commitLog:
|
||||
tmp, _ := m.GraphModel.Update(msg)
|
||||
m.GraphModel, _ = tmp.(Graph)
|
||||
|
||||
@@ -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)
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,11 @@ type (
|
||||
YearFreq Freq
|
||||
Created time.Time
|
||||
}
|
||||
|
||||
ExpRepo struct {
|
||||
Commits []Commit
|
||||
Created time.Time
|
||||
}
|
||||
WorkDay struct {
|
||||
Day time.Time `json:"day"`
|
||||
Count int `json:"count"`
|
||||
|
||||
Reference in New Issue
Block a user