refactor(daemon): ListSessions reads snapshotView
- commit
- f5a831c0c80232f984dbf6867f439bfbfd1f5ab1
- author
- brice · · 2026-07-29 19:36 UTC
- parent
- aa7c5e4
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +10 -8
M internal/usecase/daemon/control.go +10 -8
| @@ -575,17 +575,19 @@ func (e controlExec) ListSessions(asJSON bool) (string, error) { | |||
| 575 | 575 | sessions = append(sessions, sess) | |
| 576 | 576 | } | |
| 577 | 577 | e.d.mu.Unlock() | |
| 578 | - | var active *session | |
| 578 | + | snaps := make([]sessionView, 0, len(sessions)) | |
| 579 | 579 | for _, sess := range sessions { | |
| 580 | - | if active == nil || sess.mruAt.Load() > active.mruAt.Load() { | |
| 581 | - | active = sess | |
| 580 | + | snaps = append(snaps, sess.snapshotView(viewOptions{})) | |
| 581 | + | } | |
| 582 | + | activeIdx := -1 | |
| 583 | + | for i, snap := range snaps { | |
| 584 | + | if activeIdx == -1 || snap.mruAt > snaps[activeIdx].mruAt { | |
| 585 | + | activeIdx = i | |
| 582 | 586 | } | |
| 583 | 587 | } | |
| 584 | - | rows := make([]row, 0, len(sessions)) | |
| 585 | - | for _, sess := range sessions { | |
| 586 | - | sess.mu.Lock() | |
| 587 | - | rows = append(rows, row{Name: sess.name, Ephemeral: sess.ephemeral, Tabs: len(sess.tabs), Attached: sess.client != nil, Active: sess == active}) | |
| 588 | - | sess.mu.Unlock() | |
| 588 | + | rows := make([]row, 0, len(snaps)) | |
| 589 | + | for i, snap := range snaps { | |
| 590 | + | rows = append(rows, row{Name: snap.name, Ephemeral: snap.ephemeral, Tabs: snap.tabCount, Attached: snap.attached, Active: i == activeIdx}) | |
| 589 | 591 | } | |
| 590 | 592 | sort.Slice(rows, func(i, j int) bool { return rows[i].Name < rows[j].Name }) | |
| 591 | 593 | if asJSON { | |
| @@ -575,17 +575,19 @@ func (e controlExec) ListSessions(asJSON bool) (string, error) { | |||||
| 575 | sessions = append(sessions, sess) | 575 | sessions = append(sessions, sess) | ||
| 576 | } | 576 | } | ||
| 577 | e.d.mu.Unlock() | 577 | e.d.mu.Unlock() | ||
| 578 | - | var active *session | 578 | + | snaps := make([]sessionView, 0, len(sessions)) |
| 579 | for _, sess := range sessions { | 579 | for _, sess := range sessions { | ||
| 580 | - | if active == nil || sess.mruAt.Load() > active.mruAt.Load() { | 580 | + | snaps = append(snaps, sess.snapshotView(viewOptions{})) |
| 581 | - | active = sess | 581 | + | } |
| 582 | + | activeIdx := -1 | |||
| 583 | + | for i, snap := range snaps { | |||
| 584 | + | if activeIdx == -1 || snap.mruAt > snaps[activeIdx].mruAt { | |||
| 585 | + | activeIdx = i | |||
| 582 | } | 586 | } | ||
| 583 | } | 587 | } | ||
| 584 | - | rows := make([]row, 0, len(sessions)) | 588 | + | rows := make([]row, 0, len(snaps)) |
| 585 | - | for _, sess := range sessions { | 589 | + | for i, snap := range snaps { |
| 586 | - | sess.mu.Lock() | 590 | + | rows = append(rows, row{Name: snap.name, Ephemeral: snap.ephemeral, Tabs: snap.tabCount, Attached: snap.attached, Active: i == activeIdx}) |
| 587 | - | rows = append(rows, row{Name: sess.name, Ephemeral: sess.ephemeral, Tabs: len(sess.tabs), Attached: sess.client != nil, Active: sess == active}) | |||
| 588 | - | sess.mu.Unlock() | |||
| 589 | } | 591 | } | ||
| 590 | sort.Slice(rows, func(i, j int) bool { return rows[i].Name < rows[j].Name }) | 592 | sort.Slice(rows, func(i, j int) bool { return rows[i].Name < rows[j].Name }) | ||
| 591 | if asJSON { | 593 | if asJSON { | ||