From d7b5c883fec670539ceb40f3baa792bc1204f676 Mon Sep 17 00:00:00 2001 From: Andrew Lygin Date: Mon, 4 Mar 2024 21:56:17 +0300 Subject: [PATCH] Optimize project panel subscriptions (#8846) The project panel now both observes all the project updates and subscribes to project events it's interested in. The observing handler updates the list of visible entries on any notification, which looks pretty excessive. This PR removes the observer completely, and adds missing event handlers to the subscription, thus removing unnecessary work. Release Notes: - N/A --- crates/project_panel/src/project_panel.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index a065ad4b80667f2d13264c53d8c4d45d53cf3b83..481086a8bb631e5876b5253bc6c2524a963353f2 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -166,13 +166,7 @@ impl ProjectPanel { fn new(workspace: &mut Workspace, cx: &mut ViewContext) -> View { let project = workspace.project().clone(); let project_panel = cx.new_view(|cx: &mut ViewContext| { - cx.observe(&project, |this, _, cx| { - this.update_visible_entries(None, cx); - cx.notify(); - }) - .detach(); let focus_handle = cx.focus_handle(); - cx.on_focus(&focus_handle, Self::focus_in).detach(); cx.subscribe(&project, |this, project, event, cx| match event { @@ -193,6 +187,10 @@ impl ProjectPanel { this.update_visible_entries(None, cx); cx.notify(); } + project::Event::WorktreeUpdatedEntries(_, _) | project::Event::WorktreeAdded => { + this.update_visible_entries(None, cx); + cx.notify(); + } _ => {} }) .detach();