diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-07-25 04:26:55 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-25 04:26:55 +0300 |
| commit | d4e0dd3d903c50d2edb8c3cec71952a83989b310 (patch) | |
| tree | c90ec43a08fab1fc79e1d6db865c723877a051af /src/app/actions.rs | |
| parent | b33e5f973fc89381aa4ac72b3a31fa087ec66e23 (diff) | |
perf: eliminate repeated workspace git discovery (#1842)
* perf: eliminate repeated workspace git discovery
refs #1838
* fix: keep workspace labels current without extra redraws
refs #1838
* fix: retain discovered workspace git metadata
refs #1838
Diffstat (limited to 'src/app/actions.rs')
| -rw-r--r-- | src/app/actions.rs | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/src/app/actions.rs b/src/app/actions.rs index d3b85c07..0709ed4c 100644 --- a/src/app/actions.rs +++ b/src/app/actions.rs @@ -2607,11 +2607,21 @@ impl AppState { } let ws = &mut self.workspaces[ws_idx]; - if ws.cached_git_branch != result.branch { + if ws.cached_identity_cwd != result.resolved_identity_cwd { + ws.cached_identity_cwd = result.resolved_identity_cwd; + } + if ws.cached_auto_label != result.auto_label { + ws.cached_auto_label = result.auto_label; + changed |= ws.custom_name.is_none(); + } + if ws.cached_git_status_key != result.status_cache_key { + ws.cached_git_status_key = result.status_cache_key; + } + if result.demand.branch && ws.cached_git_branch != result.branch { ws.cached_git_branch = result.branch; changed = true; } - if ws.cached_git_ahead_behind != result.ahead_behind { + if result.demand.ahead_behind && ws.cached_git_ahead_behind != result.ahead_behind { ws.cached_git_ahead_behind = result.ahead_behind; changed = true; } @@ -3103,7 +3113,8 @@ impl AppState { let sound = sound_for_toast_kind(kind, suppress_active_tab_notifications) .filter(|_| self.sound.allows(known_agent)); let build_toast = || { - let workspace_label = self.workspaces[ws_idx].display_name(); + let workspace_label = + self.workspaces[ws_idx].display_name_from_terminals(&self.terminals); let context = notification_context(&self.workspaces[ws_idx], &workspace_label, ws_idx, pane_id); ToastNotification { @@ -3904,7 +3915,10 @@ mod tests { &terminal_runtimes, vec![WorkspaceGitStatus { workspace_id: first_id, - resolved_identity_cwd: first_cwd, + resolved_identity_cwd: first_cwd.clone(), + status_cache_key: first_cwd, + demand: crate::workspace::GitStatusRefreshDemand::ALL, + auto_label: "one".into(), branch: Some("main".into()), ahead_behind: Some((2, 1)), space: None, @@ -3931,6 +3945,9 @@ mod tests { vec![WorkspaceGitStatus { workspace_id, resolved_identity_cwd: std::path::PathBuf::from("/definitely/not/current"), + status_cache_key: std::path::PathBuf::from("/definitely/not/current"), + demand: crate::workspace::GitStatusRefreshDemand::ALL, + auto_label: "stale".into(), branch: Some("main".into()), ahead_behind: Some((0, 1)), space: None, @@ -3943,6 +3960,36 @@ mod tests { } #[test] + fn apply_workspace_git_statuses_ignores_unrequested_branch_changes() { + let mut state = app_with_workspaces(&["one"]); + let workspace_id = state.workspaces[0].id.clone(); + let cwd = state.workspaces[0].resolved_identity_cwd().unwrap(); + state.workspaces[0].cached_auto_label = "one".into(); + state.workspaces[0].cached_git_branch = Some("old".into()); + + let terminal_runtimes = crate::terminal::TerminalRuntimeRegistry::new(); + let changed = state.apply_workspace_git_statuses( + &terminal_runtimes, + vec![WorkspaceGitStatus { + workspace_id, + resolved_identity_cwd: cwd.clone(), + status_cache_key: cwd, + demand: crate::workspace::GitStatusRefreshDemand { + branch: false, + ahead_behind: true, + }, + auto_label: "one".into(), + branch: Some("new".into()), + ahead_behind: None, + space: None, + }], + ); + + assert!(!changed); + assert_eq!(state.workspaces[0].branch().as_deref(), Some("old")); + } + + #[test] fn apply_workspace_git_statuses_clears_missing_git_status() { let mut state = app_with_workspaces(&["one"]); let workspace_id = state.workspaces[0].id.clone(); @@ -3955,7 +4002,10 @@ mod tests { &terminal_runtimes, vec