refactor(daemon): recentSessions and paletteResults read snapshotView
- commit
- aa7c5e4b262bb0542bce0ff908c459623d4720b7
- author
- brice · · 2026-07-29 19:36 UTC
- parent
- 5090cbb
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +6 -21
M internal/usecase/daemon/palette.go +3 -6
| @@ -74,12 +74,9 @@ func (d *Daemon) paletteResults(current *session, commands []command.Command) [] | |||
| 74 | 74 | if candidate == current { | |
| 75 | 75 | continue | |
| 76 | 76 | } | |
| 77 | - | candidate.mu.Lock() | |
| 78 | - | name, createdAt, ephemeral := candidate.name, candidate.createdAt, candidate.ephemeral | |
| 79 | - | id := candidate.id | |
| 80 | - | candidate.mu.Unlock() | |
| 81 | - | if name != "" && !ephemeral { | |
| 82 | - | active = append(active, palette.NewActiveSessionResult(name, time.Unix(0, createdAt), id)) | |
| 77 | + | snap := candidate.snapshotView(viewOptions{}) | |
| 78 | + | if snap.name != "" && !snap.ephemeral { | |
| 79 | + | active = append(active, palette.NewActiveSessionResult(snap.name, time.Unix(0, snap.createdAt), snap.id)) | |
| 83 | 80 | } | |
| 84 | 81 | } | |
| 85 | 82 | sort.Slice(active, func(i, j int) bool { | |
| @@ -74,12 +74,9 @@ func (d *Daemon) paletteResults(current *session, commands []command.Command) [] | |||||
| 74 | if candidate == current { | 74 | if candidate == current { | ||
| 75 | continue | 75 | continue | ||
| 76 | } | 76 | } | ||
| 77 | - | candidate.mu.Lock() | 77 | + | snap := candidate.snapshotView(viewOptions{}) |
| 78 | - | name, createdAt, ephemeral := candidate.name, candidate.createdAt, candidate.ephemeral | 78 | + | if snap.name != "" && !snap.ephemeral { |
| 79 | - | id := candidate.id | 79 | + | active = append(active, palette.NewActiveSessionResult(snap.name, time.Unix(0, snap.createdAt), snap.id)) |
| 80 | - | candidate.mu.Unlock() | |||
| 81 | - | if name != "" && !ephemeral { | |||
| 82 | - | active = append(active, palette.NewActiveSessionResult(name, time.Unix(0, createdAt), id)) | |||
| 83 | } | 80 | } | ||
| 84 | } | 81 | } | ||
| 85 | sort.Slice(active, func(i, j int) bool { | 82 | sort.Slice(active, func(i, j int) bool { | ||
M internal/usecase/daemon/recent_sessions.go +3 -15
| @@ -27,23 +27,11 @@ func (d *Daemon) recentSessions(current *session) []recentSession { | |||
| 27 | 27 | if sess == current { | |
| 28 | 28 | continue | |
| 29 | 29 | } | |
| 30 | - | sess.mu.Lock() | |
| 31 | - | if sess.ephemeral { | |
| 32 | - | sess.mu.Unlock() | |
| 30 | + | snap := sess.snapshotView(viewOptions{}) | |
| 31 | + | if snap.ephemeral { | |
| 33 | 32 | continue | |
| 34 | 33 | } | |
| 35 | - | entry := recentSession{ | |
| 36 | - | id: sess.id, | |
| 37 | - | name: sess.name, | |
| 38 | - | mruAt: sess.mruAt.Load(), | |
| 39 | - | } | |
| 40 | - | for _, tb := range sess.tabs { | |
| 41 | - | if tb.attention { | |
| 42 | - | entry.attention = true | |
| 43 | - | break | |
| 44 | - | } | |
| 45 | - | } | |
| 46 | - | sess.mu.Unlock() | |
| 34 | + | entry := recentSession{id: snap.id, name: snap.name, mruAt: snap.mruAt, attention: snap.hasAttention} | |
| 47 | 35 | recent = append(recent, entry) | |
| 48 | 36 | } | |
| 49 | 37 | d.mu.Unlock() | |
| @@ -27,23 +27,11 @@ func (d *Daemon) recentSessions(current *session) []recentSession { | |||||
| 27 | if sess == current { | 27 | if sess == current { | ||
| 28 | continue | 28 | continue | ||
| 29 | } | 29 | } | ||
| 30 | - | sess.mu.Lock() | 30 | + | snap := sess.snapshotView(viewOptions{}) |
| 31 | - | if sess.ephemeral { | 31 | + | if snap.ephemeral { |
| 32 | - | sess.mu.Unlock() | |||
| 33 | continue | 32 | continue | ||
| 34 | } | 33 | } | ||
| 35 | - | entry := recentSession{ | 34 | + | entry := recentSession{id: snap.id, name: snap.name, mruAt: snap.mruAt, attention: snap.hasAttention} |
| 36 | - | id: sess.id, | |||
| 37 | - | name: sess.name, | |||
| 38 | - | mruAt: sess.mruAt.Load(), | |||
| 39 | - | } | |||
| 40 | - | for _, tb := range sess.tabs { | |||
| 41 | - | if tb.attention { | |||
| 42 | - | entry.attention = true | |||
| 43 | - | break | |||
| 44 | - | } | |||
| 45 | - | } | |||
| 46 | - | sess.mu.Unlock() | |||
| 47 | recent = append(recent, entry) | 35 | recent = append(recent, entry) | ||
| 48 | } | 36 | } | ||
| 49 | d.mu.Unlock() | 37 | d.mu.Unlock() | ||