Skip to content

Commit 9884a85

Browse files
zanetworkerclaude
andcommitted
perf: cache session discovery for starred tab
openStarred reuses cached sessions from the last openSessions call instead of re-scanning all session directories. Cache is invalidated on star/unstar and scope toggle. First open still does one discovery; subsequent switches between Sessions and Starred are instant. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6b4f2a7 commit 9884a85

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

internal/frontend/tui/app.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ type App struct {
9090
logsView *views.LogsView
9191
costsView *views.CostsView
9292
teamsView *views.TeamsView
93-
sessionsView *views.SessionsView
94-
starredView *views.SessionsView
95-
helpView *views.HelpView
93+
sessionsView *views.SessionsView
94+
starredView *views.SessionsView
95+
cachedSessions []history.Session
96+
helpView *views.HelpView
9697
healthView *views.HealthView
9798

9899
// Layout
@@ -617,6 +618,7 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
617618
dir = a.sessionsView.CurrentDir()
618619
}
619620
sessions, _ := history.Discover(history.DiscoverOpts{Dir: dir}, "")
621+
a.cachedSessions = sessions
620622
a.sessionsView.SetSessions(sessions)
621623
a.sessionsView.SetTagVocab(history.CollectTags(""))
622624
case views.SessionAnnotateMsg:
@@ -632,6 +634,7 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
632634
meta := history.LoadMeta(msg.Session.FilePath)
633635
meta.Starred = msg.Starred
634636
_ = history.SaveMeta(msg.Session.FilePath, meta)
637+
a.cachedSessions = nil
635638
if msg.Starred {
636639
a.statusHint = "Session pinned ★"
637640
} else {
@@ -2482,9 +2485,9 @@ func (a App) openSessions() (tea.Model, tea.Cmd) {
24822485
}
24832486
}
24842487

2485-
// Discover sessions in background
24862488
opts := history.DiscoverOpts{Dir: dir}
24872489
sessions, _ := history.Discover(opts, "")
2490+
a.cachedSessions = sessions
24882491
a.sessionsView.SetSessions(sessions)
24892492
a.sessionsView.SetTagVocab(history.CollectTags(""))
24902493

@@ -2499,7 +2502,11 @@ func (a App) openStarred() (tea.Model, tea.Cmd) {
24992502
}
25002503
}
25012504

2502-
allSessions, _ := history.Discover(history.DiscoverOpts{}, "")
2505+
allSessions := a.cachedSessions
2506+
if len(allSessions) == 0 {
2507+
allSessions, _ = history.Discover(history.DiscoverOpts{}, "")
2508+
a.cachedSessions = allSessions
2509+
}
25032510
var starred []history.Session
25042511
for _, s := range allSessions {
25052512
if s.Starred {

0 commit comments

Comments
 (0)