Skip to content

Commit b4c0a4e

Browse files
authored
Merge pull request #6 from ryo246912/refactor/cache
refactor: add log cache
2 parents 8ec87c4 + b9658ae commit b4c0a4e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

internal/tui/app.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ type App struct {
126126
currentRun *models.WorkflowRun
127127
currentJobs []models.Job
128128
logs string
129+
logsCache map[int64]string // runID -> logs (session cache)
129130

130131
// Lists
131132
workflowList list.Model
@@ -219,6 +220,7 @@ func NewApp(client *github.Client, owner, repo string) *App {
219220
allRunsPage: 1,
220221
allRunsPerPage: 100,
221222
jobsCache: NewJobsCache(10 * time.Minute),
223+
logsCache: make(map[int64]string),
222224
workflowFileCache: make(map[string]string),
223225
}
224226
}
@@ -756,6 +758,8 @@ func (a *App) refresh() (tea.Model, tea.Cmd) {
756758
if a.currentRun != nil {
757759
a.logOffset = 0
758760
a.logs = ""
761+
// 強制再取得のためキャッシュ削除
762+
delete(a.logsCache, a.currentRun.ID)
759763
return a, a.loadWorkflowRunLogs(a.currentRun.ID)
760764
}
761765
}
@@ -1322,10 +1326,16 @@ func (a *App) loadWorkflowRuns(workflowID int64) tea.Cmd {
13221326

13231327
func (a *App) loadWorkflowRunLogs(runID int64) tea.Cmd {
13241328
return tea.Cmd(func() tea.Msg {
1329+
// キャッシュヒット時は即返す
1330+
if cached, ok := a.logsCache[runID]; ok {
1331+
return logsLoadedMsg{logs: cached}
1332+
}
13251333
logs, err := a.client.GetWorkflowRunLogs(a.owner, a.repo, runID)
13261334
if err != nil {
13271335
return errorMsg{err: err}
13281336
}
1337+
// キャッシュ保存
1338+
a.logsCache[runID] = logs
13291339
return logsLoadedMsg{logs: logs}
13301340
})
13311341
}

0 commit comments

Comments
 (0)