Optimize project panel subscriptions (#8846)

Andrew Lygin created

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

Change summary

crates/project_panel/src/project_panel.rs | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

Detailed changes

crates/project_panel/src/project_panel.rs 🔗

@@ -166,13 +166,7 @@ impl ProjectPanel {
     fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
         let project = workspace.project().clone();
         let project_panel = cx.new_view(|cx: &mut ViewContext<Self>| {
-            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();