Browse Source

chore: bump up collab version (#2736)

Nathan.fooo 1 year ago
parent
commit
6e27d551d9

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

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

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

@@ -85,7 +85,7 @@ checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
 [[package]]
 name = "appflowy-integrate"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "anyhow",
  "collab",
@@ -887,7 +887,7 @@ dependencies = [
 [[package]]
 name = "collab"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "anyhow",
  "bytes",
@@ -905,7 +905,7 @@ dependencies = [
 [[package]]
 name = "collab-client-ws"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "bytes",
  "collab-sync",
@@ -923,7 +923,7 @@ dependencies = [
 [[package]]
 name = "collab-database"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "anyhow",
  "async-trait",
@@ -949,7 +949,7 @@ dependencies = [
 [[package]]
 name = "collab-derive"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -961,7 +961,7 @@ dependencies = [
 [[package]]
 name = "collab-document"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "anyhow",
  "collab",
@@ -978,7 +978,7 @@ dependencies = [
 [[package]]
 name = "collab-folder"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "anyhow",
  "collab",
@@ -997,7 +997,7 @@ dependencies = [
 [[package]]
 name = "collab-persistence"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "bincode",
  "chrono",
@@ -1017,7 +1017,7 @@ dependencies = [
 [[package]]
 name = "collab-plugins"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "anyhow",
  "async-trait",
@@ -1048,7 +1048,7 @@ dependencies = [
 [[package]]
 name = "collab-sync"
 version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=c611b6#c611b6639ba089f7a24705ccb5904ed1b33be538"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=046a91#046a916cc357f4b6c88f4f5a66a84ca0e14c3c62"
 dependencies = [
  "bytes",
  "collab",

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

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

+ 28 - 40
frontend/rust-lib/flowy-core/src/deps_resolve/collab_deps.rs

@@ -1,8 +1,7 @@
 use std::sync::Arc;
 
 use appflowy_integrate::{
-  calculate_snapshot_diff, try_encode_snapshot, CollabSnapshot, MutexCollab, PersistenceError,
-  Snapshot, SnapshotDB,
+  calculate_snapshot_diff, CollabSnapshot, PersistenceError, SnapshotPersistence,
 };
 use diesel::SqliteConnection;
 
@@ -17,7 +16,7 @@ use lib_infra::util::timestamp;
 
 pub struct SnapshotDBImpl(pub Arc<UserSession>);
 
-impl SnapshotDB for SnapshotDBImpl {
+impl SnapshotPersistence for SnapshotDBImpl {
   fn get_snapshots(&self, _uid: i64, object_id: &str) -> Vec<CollabSnapshot> {
     self
       .0
@@ -36,8 +35,7 @@ impl SnapshotDB for SnapshotDBImpl {
     object_id: &str,
     title: String,
     collab_type: String,
-    snapshot: Snapshot,
-    collab: Arc<MutexCollab>,
+    snapshot_data: Vec<u8>,
   ) -> Result<(), PersistenceError> {
     let object_id = object_id.to_string();
     let weak_pool = Arc::downgrade(
@@ -53,41 +51,31 @@ impl SnapshotDB for SnapshotDBImpl {
           .get()
           .map_err(|e| PersistenceError::Internal(Box::new(e)))?;
 
-        // Try to acquire a txn lock, if failed, it means there is a txn running, so we just ignore this snapshot
-        let result = try_encode_snapshot(
-          &collab
-            .lock()
-            .try_transaction()
-            .map_err(|e| PersistenceError::Internal(Box::new(e)))?,
-          snapshot,
-        );
-
-        match result.and_then(|new_snapshot_data| {
-          let desc = match CollabSnapshotTableSql::get_latest_snapshot(&object_id, &conn) {
-            None => Ok("".to_string()),
-            Some(old_snapshot) => {
-              calculate_snapshot_diff(uid, &object_id, &old_snapshot.data, &new_snapshot_data)
-            },
-          }
-          .map_err(|e| PersistenceError::InvalidData(format!("{:?}", e)))?;
-
-          // Save the snapshot to disk
-          CollabSnapshotTableSql::create(
-            CollabSnapshotRow {
-              id: uuid::Uuid::new_v4().to_string(),
-              object_id: object_id.clone(),
-              title,
-              desc,
-              collab_type,
-              timestamp: timestamp(),
-              data: new_snapshot_data,
-            },
-            &conn,
-          )
-          .map_err(|e| PersistenceError::Internal(Box::new(e)))
-        }) {
-          Ok(_) => {},
-          Err(e) => tracing::error!("create snapshot error: {:?}", e),
+        let desc = match CollabSnapshotTableSql::get_latest_snapshot(&object_id, &conn) {
+          None => Ok("".to_string()),
+          Some(old_snapshot) => {
+            calculate_snapshot_diff(uid, &object_id, &old_snapshot.data, &snapshot_data)
+          },
+        }
+        .map_err(|e| PersistenceError::InvalidData(format!("{:?}", e)))?;
+
+        // Save the snapshot data to disk
+        let result = CollabSnapshotTableSql::create(
+          CollabSnapshotRow {
+            id: uuid::Uuid::new_v4().to_string(),
+            object_id: object_id.clone(),
+            title,
+            desc,
+            collab_type,
+            timestamp: timestamp(),
+            data: snapshot_data,
+          },
+          &conn,
+        )
+        .map_err(|e| PersistenceError::Internal(Box::new(e)));
+
+        if let Err(e) = result {
+          tracing::error!("create snapshot error: {:?}", e);
         }
       }
       Ok::<(), PersistenceError>(())

+ 11 - 12
frontend/rust-lib/flowy-database2/src/services/field/type_options/checkbox_type_option/checkbox_type_option.rs

@@ -1,3 +1,13 @@
+use std::cmp::Ordering;
+use std::str::FromStr;
+
+use collab::core::any_map::AnyMapExtension;
+use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder};
+use collab_database::rows::Cell;
+use serde::{Deserialize, Serialize};
+
+use flowy_error::FlowyResult;
+
 use crate::entities::{CheckboxFilterPB, FieldType};
 use crate::services::cell::{CellDataChangeset, CellDataDecoder};
 use crate::services::field::{
@@ -5,14 +15,6 @@ use crate::services::field::{
   TypeOptionCellDataFilter, TypeOptionTransform,
 };
 
-use collab::core::any_map::AnyMapExtension;
-use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder};
-use collab_database::rows::Cell;
-use flowy_error::FlowyResult;
-use serde::{Deserialize, Serialize};
-use std::cmp::Ordering;
-use std::str::FromStr;
-
 #[derive(Debug, Clone, Serialize, Deserialize, Default)]
 pub struct CheckboxTypeOption {
   pub is_selected: bool,
@@ -89,10 +91,7 @@ impl CellDataDecoder for CheckboxTypeOption {
     if !decoded_field_type.is_checkbox() {
       return Ok(Default::default());
     }
-
-    let cell = self.parse_cell(cell);
-    println!("cell: {:?}", cell);
-    return cell;
+    self.parse_cell(cell)
   }
 
   fn stringify_cell_data(&self, cell_data: <Self as TypeOption>::CellData) -> String {

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

@@ -42,7 +42,7 @@ pub(crate) async fn open_workspace_handler(
     None => Err(FlowyError::workspace_id().context("workspace id should not be empty")),
     Some(workspace_id) => {
       if workspace_id.is_empty() {
-        return Err(FlowyError::workspace_id().context("workspace id should not be empty"));
+        Err(FlowyError::workspace_id().context("workspace id should not be empty"))
       } else {
         let workspace = folder.open_workspace(&workspace_id).await?;
         let views = folder.get_workspace_views(&workspace_id).await?;

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

@@ -66,7 +66,7 @@ impl Folder2Manager {
     self.with_folder(Err(FlowyError::internal()), |folder| {
       let workspace_pb_from_workspace = |workspace: Workspace, folder: &Folder| {
         let views = get_workspace_view_pbs(&workspace.id, folder);
-        let workspace: WorkspacePB = (workspace.clone(), views).into();
+        let workspace: WorkspacePB = (workspace, views).into();
         Ok::<WorkspacePB, FlowyError>(workspace)
       };
 
@@ -317,12 +317,6 @@ impl Folder2Manager {
         created_at: timestamp(),
       }]);
 
-      if let Some(view) = folder.get_current_view() {
-        if view == view_id {
-          folder.set_current_view("");
-        }
-      }
-
       // notify the parent view that the view is moved to trash
       send_notification(view_id, FolderNotification::DidMoveViewToTrash)
         .payload(DeletedViewPB {

+ 4 - 2
frontend/rust-lib/flowy-test/tests/database/test.rs

@@ -1,10 +1,12 @@
+use std::convert::TryFrom;
+
 use bytes::Bytes;
+
 use flowy_database2::entities::{
   CellChangesetPB, DatabaseLayoutPB, DatabaseViewIdPB, FieldType, SelectOptionCellDataPB,
 };
 use flowy_test::event_builder::EventBuilder;
 use flowy_test::FlowyCoreTest;
-use std::convert::TryFrom;
 
 #[tokio::test]
 async fn get_database_id_event_test() {
@@ -248,7 +250,7 @@ async fn update_checkbox_cell_event_test() {
   let field_id = fields[2].id.clone();
   assert_eq!(fields[2].field_type, FieldType::Checkbox);
 
-  for input in vec!["yes", "true", "1"] {
+  for input in &["yes", "true", "1"] {
     let error = test
       .update_cell(CellChangesetPB {
         view_id: grid_view.id.clone(),