Explorar el Código

feat: using cached view (#2877)

Nathan.fooo hace 1 año
padre
commit
88faa0f02a

+ 6 - 6
frontend/appflowy_tauri/src-tauri/Cargo.toml

@@ -34,12 +34,12 @@ default = ["custom-protocol"]
 custom-protocol = ["tauri/custom-protocol"]
 custom-protocol = ["tauri/custom-protocol"]
 
 
 [patch.crates-io]
 [patch.crates-io]
-collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
-collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
-collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
-collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
-collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
-appflowy-integrate = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
+collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
+collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
+collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
+collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
+collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
+appflowy-integrate = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
 
 
 #collab = { path = "../../AppFlowy-Collab/collab" }
 #collab = { path = "../../AppFlowy-Collab/collab" }
 #collab-folder = { path = "../../AppFlowy-Collab/collab-folder" }
 #collab-folder = { path = "../../AppFlowy-Collab/collab-folder" }

+ 0 - 10
frontend/rust-lib/Cargo.lock

@@ -85,7 +85,6 @@ checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
 [[package]]
 [[package]]
 name = "appflowy-integrate"
 name = "appflowy-integrate"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "anyhow",
  "anyhow",
  "collab",
  "collab",
@@ -887,7 +886,6 @@ dependencies = [
 [[package]]
 [[package]]
 name = "collab"
 name = "collab"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "anyhow",
  "anyhow",
  "bytes",
  "bytes",
@@ -905,7 +903,6 @@ dependencies = [
 [[package]]
 [[package]]
 name = "collab-client-ws"
 name = "collab-client-ws"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "bytes",
  "bytes",
  "collab-sync",
  "collab-sync",
@@ -923,7 +920,6 @@ dependencies = [
 [[package]]
 [[package]]
 name = "collab-database"
 name = "collab-database"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "anyhow",
  "anyhow",
  "async-trait",
  "async-trait",
@@ -949,7 +945,6 @@ dependencies = [
 [[package]]
 [[package]]
 name = "collab-derive"
 name = "collab-derive"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "proc-macro2",
  "proc-macro2",
  "quote",
  "quote",
@@ -961,7 +956,6 @@ dependencies = [
 [[package]]
 [[package]]
 name = "collab-document"
 name = "collab-document"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "anyhow",
  "anyhow",
  "collab",
  "collab",
@@ -979,7 +973,6 @@ dependencies = [
 [[package]]
 [[package]]
 name = "collab-folder"
 name = "collab-folder"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "anyhow",
  "anyhow",
  "chrono",
  "chrono",
@@ -999,7 +992,6 @@ dependencies = [
 [[package]]
 [[package]]
 name = "collab-persistence"
 name = "collab-persistence"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "bincode",
  "bincode",
  "chrono",
  "chrono",
@@ -1019,7 +1011,6 @@ dependencies = [
 [[package]]
 [[package]]
 name = "collab-plugins"
 name = "collab-plugins"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "anyhow",
  "anyhow",
  "async-trait",
  "async-trait",
@@ -1050,7 +1041,6 @@ dependencies = [
 [[package]]
 [[package]]
 name = "collab-sync"
 name = "collab-sync"
 version = "0.1.0"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=06e942#06e942cb6433c94b5ecfe1d431b64bba625fc09c"
 dependencies = [
 dependencies = [
  "bytes",
  "bytes",
  "collab",
  "collab",

+ 5 - 5
frontend/rust-lib/Cargo.toml

@@ -33,11 +33,11 @@ opt-level = 3
 incremental = false
 incremental = false
 
 
 [patch.crates-io]
 [patch.crates-io]
-collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
-collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
-collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
-collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
-appflowy-integrate = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "06e942" }
+collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
+collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
+collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
+collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
+appflowy-integrate = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d1882d" }
 
 
 #collab = { path = "../AppFlowy-Collab/collab" }
 #collab = { path = "../AppFlowy-Collab/collab" }
 #collab-folder = { path = "../AppFlowy-Collab/collab-folder" }
 #collab-folder = { path = "../AppFlowy-Collab/collab-folder" }

+ 1 - 1
frontend/rust-lib/flowy-document2/src/manager.rs

@@ -63,7 +63,7 @@ impl DocumentManager {
     }
     }
     tracing::debug!("open_document: {:?}", doc_id);
     tracing::debug!("open_document: {:?}", doc_id);
     // read the existing document from the disk.
     // read the existing document from the disk.
-    let document = self.get_document_from_disk(&doc_id)?;
+    let document = self.get_document_from_disk(doc_id)?;
     // save the document to the memory and read it from the memory if we open the same document again.
     // save the document to the memory and read it from the memory if we open the same document again.
     // and we don't want to subscribe to the document changes if we open the same document again.
     // and we don't want to subscribe to the document changes if we open the same document again.
     self
     self

+ 15 - 14
frontend/rust-lib/flowy-folder2/src/entities/view.rs

@@ -1,6 +1,7 @@
 use std::collections::HashMap;
 use std::collections::HashMap;
 use std::convert::TryInto;
 use std::convert::TryInto;
 use std::ops::{Deref, DerefMut};
 use std::ops::{Deref, DerefMut};
+use std::sync::Arc;
 
 
 use collab_folder::core::{View, ViewLayout};
 use collab_folder::core::{View, ViewLayout};
 
 
@@ -59,33 +60,33 @@ pub struct ViewPB {
   pub cover_url: Option<String>,
   pub cover_url: Option<String>,
 }
 }
 
 
-pub fn view_pb_without_child_views(view: View) -> ViewPB {
+pub fn view_pb_without_child_views(view: Arc<View>) -> ViewPB {
   ViewPB {
   ViewPB {
-    id: view.id,
-    parent_view_id: view.parent_view_id,
-    name: view.name,
+    id: view.id.clone(),
+    parent_view_id: view.parent_view_id.clone(),
+    name: view.name.clone(),
     create_time: view.created_at,
     create_time: view.created_at,
     child_views: Default::default(),
     child_views: Default::default(),
-    layout: view.layout.into(),
-    icon_url: view.icon_url,
-    cover_url: view.cover_url,
+    layout: view.layout.clone().into(),
+    icon_url: view.icon_url.clone(),
+    cover_url: view.cover_url.clone(),
   }
   }
 }
 }
 
 
 /// Returns a ViewPB with child views. Only the first level of child views are included.
 /// Returns a ViewPB with child views. Only the first level of child views are included.
-pub fn view_pb_with_child_views(view: View, child_views: Vec<View>) -> ViewPB {
+pub fn view_pb_with_child_views(view: Arc<View>, child_views: Vec<Arc<View>>) -> ViewPB {
   ViewPB {
   ViewPB {
-    id: view.id,
-    parent_view_id: view.parent_view_id,
-    name: view.name,
+    id: view.id.clone(),
+    parent_view_id: view.parent_view_id.clone(),
+    name: view.name.clone(),
     create_time: view.created_at,
     create_time: view.created_at,
     child_views: child_views
     child_views: child_views
       .into_iter()
       .into_iter()
       .map(view_pb_without_child_views)
       .map(view_pb_without_child_views)
       .collect(),
       .collect(),
-    layout: view.layout.into(),
-    icon_url: view.icon_url,
-    cover_url: view.cover_url,
+    layout: view.layout.clone().into(),
+    icon_url: view.icon_url.clone(),
+    cover_url: view.cover_url.clone(),
   }
   }
 }
 }
 
 

+ 2 - 2
frontend/rust-lib/flowy-folder2/src/event_handler.rs

@@ -87,7 +87,7 @@ pub(crate) async fn create_view_handler(
   if set_as_current {
   if set_as_current {
     let _ = folder.set_current_view(&view.id).await;
     let _ = folder.set_current_view(&view.id).await;
   }
   }
-  data_result_ok(view_pb_without_child_views(view))
+  data_result_ok(view_pb_without_child_views(Arc::new(view)))
 }
 }
 
 
 pub(crate) async fn create_orphan_view_handler(
 pub(crate) async fn create_orphan_view_handler(
@@ -100,7 +100,7 @@ pub(crate) async fn create_orphan_view_handler(
   if set_as_current {
   if set_as_current {
     let _ = folder.set_current_view(&view.id).await;
     let _ = folder.set_current_view(&view.id).await;
   }
   }
-  data_result_ok(view_pb_without_child_views(view))
+  data_result_ok(view_pb_without_child_views(Arc::new(view)))
 }
 }
 
 
 pub(crate) async fn read_view_handler(
 pub(crate) async fn read_view_handler(

+ 10 - 14
frontend/rust-lib/flowy-folder2/src/manager.rs

@@ -313,14 +313,13 @@ impl Folder2Manager {
 
 
     match folder.views.get_view(&view_id) {
     match folder.views.get_view(&view_id) {
       None => Err(FlowyError::record_not_found()),
       None => Err(FlowyError::record_not_found()),
-      Some(mut view) => {
-        view.children.retain(|b| !trash_ids.contains(&b.id));
+      Some(view) => {
         let child_views = folder
         let child_views = folder
           .views
           .views
           .get_views_belong_to(&view.id)
           .get_views_belong_to(&view.id)
           .into_iter()
           .into_iter()
           .filter(|view| !trash_ids.contains(&view.id))
           .filter(|view| !trash_ids.contains(&view.id))
-          .collect::<Vec<View>>();
+          .collect::<Vec<_>>();
         let view_pb = view_pb_with_child_views(view, child_views);
         let view_pb = view_pb_with_child_views(view, child_views);
         Ok(view_pb)
         Ok(view_pb)
       },
       },
@@ -402,7 +401,7 @@ impl Folder2Manager {
 
 
   /// Return a list of views that belong to the given parent view id.
   /// Return a list of views that belong to the given parent view id.
   #[tracing::instrument(level = "debug", skip(self, parent_view_id), err)]
   #[tracing::instrument(level = "debug", skip(self, parent_view_id), err)]
-  pub async fn get_views_belong_to(&self, parent_view_id: &str) -> FlowyResult<Vec<View>> {
+  pub async fn get_views_belong_to(&self, parent_view_id: &str) -> FlowyResult<Vec<Arc<View>>> {
     let views = self.with_folder(vec![], |folder| {
     let views = self.with_folder(vec![], |folder| {
       folder.views.get_views_belong_to(parent_view_id)
       folder.views.get_views_belong_to(parent_view_id)
     });
     });
@@ -434,10 +433,6 @@ impl Folder2Manager {
     }
     }
 
 
     if let Ok(view_pb) = self.get_view(&params.view_id).await {
     if let Ok(view_pb) = self.get_view(&params.view_id).await {
-      notify_parent_view_did_change(
-        self.mutex_folder.clone(),
-        vec![view_pb.parent_view_id.clone()],
-      );
       send_notification(&view_pb.id, FolderNotification::DidUpdateView)
       send_notification(&view_pb.id, FolderNotification::DidUpdateView)
         .payload(view_pb)
         .payload(view_pb)
         .send();
         .send();
@@ -457,8 +452,8 @@ impl Folder2Manager {
     let duplicate_params = CreateViewParams {
     let duplicate_params = CreateViewParams {
       parent_view_id: view.parent_view_id.clone(),
       parent_view_id: view.parent_view_id.clone(),
       name: format!("{} (copy)", &view.name),
       name: format!("{} (copy)", &view.name),
-      desc: view.desc,
-      layout: view.layout.into(),
+      desc: view.desc.clone(),
+      layout: view.layout.clone().into(),
       initial_data: view_data.to_vec(),
       initial_data: view_data.to_vec(),
       view_id: gen_view_id(),
       view_id: gen_view_id(),
       meta: Default::default(),
       meta: Default::default(),
@@ -619,10 +614,11 @@ impl Folder2Manager {
         }),
         }),
         Some(parent_view) => Some((
         Some(parent_view) => Some((
           false,
           false,
-          parent_view.id,
+          parent_view.id.clone(),
           parent_view
           parent_view
             .children
             .children
             .items
             .items
+            .clone()
             .into_iter()
             .into_iter()
             .map(|view| view.id)
             .map(|view| view.id)
             .collect::<Vec<String>>(),
             .collect::<Vec<String>>(),
@@ -642,7 +638,7 @@ fn listen_on_view_change(mut rx: ViewChangeReceiver, weak_mutex_folder: &Weak<Mu
         match value {
         match value {
           ViewChange::DidCreateView { view } => {
           ViewChange::DidCreateView { view } => {
             notify_child_views_changed(
             notify_child_views_changed(
-              view_pb_without_child_views(view.clone()),
+              view_pb_without_child_views(Arc::new(view.clone())),
               ChildViewChangeReason::DidCreateView,
               ChildViewChangeReason::DidCreateView,
             );
             );
             notify_parent_view_did_change(folder.clone(), vec![view.parent_view_id]);
             notify_parent_view_did_change(folder.clone(), vec![view.parent_view_id]);
@@ -657,7 +653,7 @@ fn listen_on_view_change(mut rx: ViewChangeReceiver, weak_mutex_folder: &Weak<Mu
           },
           },
           ViewChange::DidUpdate { view } => {
           ViewChange::DidUpdate { view } => {
             notify_child_views_changed(
             notify_child_views_changed(
-              view_pb_without_child_views(view.clone()),
+              view_pb_without_child_views(Arc::new(view.clone())),
               ChildViewChangeReason::DidUpdateView,
               ChildViewChangeReason::DidUpdateView,
             );
             );
             notify_parent_view_did_change(folder.clone(), vec![view.parent_view_id]);
             notify_parent_view_did_change(folder.clone(), vec![view.parent_view_id]);
@@ -707,7 +703,7 @@ fn listen_on_trash_change(mut rx: TrashChangeReceiver, weak_mutex_folder: &Weak<
         if let Some(folder) = folder.lock().as_ref() {
         if let Some(folder) = folder.lock().as_ref() {
           let views = folder.views.get_views(&ids);
           let views = folder.views.get_views(&ids);
           for view in views {
           for view in views {
-            unique_ids.insert(view.parent_view_id);
+            unique_ids.insert(view.parent_view_id.clone());
           }
           }
 
 
           let repeated_trash: RepeatedTrashPB = folder.get_all_trash().into();
           let repeated_trash: RepeatedTrashPB = folder.get_all_trash().into();

+ 3 - 1
frontend/rust-lib/flowy-folder2/src/notification.rs

@@ -1,3 +1,5 @@
+use std::sync::Arc;
+
 use collab_folder::core::{View, Workspace};
 use collab_folder::core::{View, Workspace};
 
 
 use flowy_derive::ProtoBuf_Enum;
 use flowy_derive::ProtoBuf_Enum;
@@ -54,7 +56,7 @@ pub(crate) fn send_workspace_notification<T: ToBytes>(ty: FolderNotification, pa
 
 
 pub(crate) fn send_workspace_setting_notification(
 pub(crate) fn send_workspace_setting_notification(
   current_workspace: Option<Workspace>,
   current_workspace: Option<Workspace>,
-  current_view: Option<View>,
+  current_view: Option<Arc<View>>,
 ) -> Option<()> {
 ) -> Option<()> {
   let workspace: WorkspacePB = current_workspace?.into();
   let workspace: WorkspacePB = current_workspace?.into();
   let latest_view = current_view.map(view_pb_without_child_views);
   let latest_view = current_view.map(view_pb_without_child_views);

+ 4 - 4
frontend/rust-lib/flowy-folder2/src/user_default.rs

@@ -1,6 +1,6 @@
 use std::sync::Arc;
 use std::sync::Arc;
 
 
-use collab_folder::core::{FolderData, RepeatedView, ViewIdentifier, Workspace};
+use collab_folder::core::{FolderData, RepeatedViewIdentifier, ViewIdentifier, Workspace};
 use tokio::sync::RwLock;
 use tokio::sync::RwLock;
 
 
 use lib_infra::util::timestamp;
 use lib_infra::util::timestamp;
@@ -46,7 +46,7 @@ impl DefaultFolderBuilder {
     let workspace = Workspace {
     let workspace = Workspace {
       id: workspace_id,
       id: workspace_id,
       name: "Workspace".to_string(),
       name: "Workspace".to_string(),
-      child_views: RepeatedView::new(first_level_views),
+      child_views: RepeatedViewIdentifier::new(first_level_views),
       created_at: timestamp(),
       created_at: timestamp(),
     };
     };
 
 
@@ -78,11 +78,11 @@ pub fn gen_workspace_id() -> String {
 impl From<&ParentChildViews> for ViewPB {
 impl From<&ParentChildViews> for ViewPB {
   fn from(value: &ParentChildViews) -> Self {
   fn from(value: &ParentChildViews) -> Self {
     view_pb_with_child_views(
     view_pb_with_child_views(
-      value.parent_view.clone(),
+      Arc::new(value.parent_view.clone()),
       value
       value
         .child_views
         .child_views
         .iter()
         .iter()
-        .map(|v| v.parent_view.clone())
+        .map(|v| Arc::new(v.parent_view.clone()))
         .collect(),
         .collect(),
     )
     )
   }
   }

+ 2 - 2
frontend/rust-lib/flowy-folder2/src/view_operation.rs

@@ -4,7 +4,7 @@ use std::sync::Arc;
 
 
 use bytes::Bytes;
 use bytes::Bytes;
 pub use collab_folder::core::View;
 pub use collab_folder::core::View;
-use collab_folder::core::{RepeatedView, ViewIdentifier, ViewLayout};
+use collab_folder::core::{RepeatedViewIdentifier, ViewIdentifier, ViewLayout};
 use tokio::sync::RwLock;
 use tokio::sync::RwLock;
 
 
 use flowy_error::FlowyError;
 use flowy_error::FlowyError;
@@ -113,7 +113,7 @@ impl ViewBuilder {
       layout: self.layout,
       layout: self.layout,
       icon_url: self.icon_url,
       icon_url: self.icon_url,
       cover_url: self.cover_url,
       cover_url: self.cover_url,
-      children: RepeatedView::new(
+      children: RepeatedViewIdentifier::new(
         self
         self
           .child_views
           .child_views
           .iter()
           .iter()