diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.lock b/frontend/appflowy_tauri/src-tauri/Cargo.lock index 6dec2af6b2..7742a1a97e 100644 --- a/frontend/appflowy_tauri/src-tauri/Cargo.lock +++ b/frontend/appflowy_tauri/src-tauri/Cargo.lock @@ -964,7 +964,7 @@ dependencies = [ [[package]] name = "collab" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "arc-swap", @@ -989,7 +989,7 @@ dependencies = [ [[package]] name = "collab-database" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "async-trait", @@ -1018,7 +1018,7 @@ dependencies = [ [[package]] name = "collab-document" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "arc-swap", @@ -1038,7 +1038,7 @@ dependencies = [ [[package]] name = "collab-entity" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "bytes", @@ -1057,7 +1057,7 @@ dependencies = [ [[package]] name = "collab-folder" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "arc-swap", @@ -1100,7 +1100,7 @@ dependencies = [ [[package]] name = "collab-plugins" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "async-stream", @@ -1180,7 +1180,7 @@ dependencies = [ [[package]] name = "collab-user" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "collab", diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.toml b/frontend/appflowy_tauri/src-tauri/Cargo.toml index 7df92350f2..4ccae6608a 100644 --- a/frontend/appflowy_tauri/src-tauri/Cargo.toml +++ b/frontend/appflowy_tauri/src-tauri/Cargo.toml @@ -116,13 +116,13 @@ custom-protocol = ["tauri/custom-protocol"] # To switch to the local path, run: # scripts/tool/update_collab_source.sh # ⚠️⚠️⚠️️ -collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } +collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } # Working directory: frontend # To update the commit ID, run: diff --git a/frontend/appflowy_web_app/src-tauri/Cargo.lock b/frontend/appflowy_web_app/src-tauri/Cargo.lock index f93f6e1f7e..5558447843 100644 --- a/frontend/appflowy_web_app/src-tauri/Cargo.lock +++ b/frontend/appflowy_web_app/src-tauri/Cargo.lock @@ -947,7 +947,7 @@ dependencies = [ [[package]] name = "collab" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "arc-swap", @@ -972,7 +972,7 @@ dependencies = [ [[package]] name = "collab-database" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "async-trait", @@ -1001,7 +1001,7 @@ dependencies = [ [[package]] name = "collab-document" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "arc-swap", @@ -1021,7 +1021,7 @@ dependencies = [ [[package]] name = "collab-entity" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "bytes", @@ -1040,7 +1040,7 @@ dependencies = [ [[package]] name = "collab-folder" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "arc-swap", @@ -1083,7 +1083,7 @@ dependencies = [ [[package]] name = "collab-plugins" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "async-stream", @@ -1163,7 +1163,7 @@ dependencies = [ [[package]] name = "collab-user" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "collab", diff --git a/frontend/appflowy_web_app/src-tauri/Cargo.toml b/frontend/appflowy_web_app/src-tauri/Cargo.toml index d416b518ad..9a430039dd 100644 --- a/frontend/appflowy_web_app/src-tauri/Cargo.toml +++ b/frontend/appflowy_web_app/src-tauri/Cargo.toml @@ -116,13 +116,13 @@ custom-protocol = ["tauri/custom-protocol"] # To switch to the local path, run: # scripts/tool/update_collab_source.sh # ⚠️⚠️⚠️️ -collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } +collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } # Working directory: frontend # To update the commit ID, run: diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock index d7c8ed1a2a..489786a65f 100644 --- a/frontend/rust-lib/Cargo.lock +++ b/frontend/rust-lib/Cargo.lock @@ -825,7 +825,7 @@ dependencies = [ [[package]] name = "collab" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "arc-swap", @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "collab-database" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "async-trait", @@ -879,7 +879,7 @@ dependencies = [ [[package]] name = "collab-document" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "arc-swap", @@ -899,7 +899,7 @@ dependencies = [ [[package]] name = "collab-entity" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "bytes", @@ -918,7 +918,7 @@ dependencies = [ [[package]] name = "collab-folder" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "arc-swap", @@ -961,7 +961,7 @@ dependencies = [ [[package]] name = "collab-plugins" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "async-stream", @@ -1041,7 +1041,7 @@ dependencies = [ [[package]] name = "collab-user" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=6f98f054a8306a8791b65bf1825091ab3fe60166#6f98f054a8306a8791b65bf1825091ab3fe60166" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=79e649061da9245d81b9114f3aaaf0064c265c97#79e649061da9245d81b9114f3aaaf0064c265c97" dependencies = [ "anyhow", "collab", diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.toml index b0c38f4a4d..e8a4c0acf9 100644 --- a/frontend/rust-lib/Cargo.toml +++ b/frontend/rust-lib/Cargo.toml @@ -136,13 +136,13 @@ rocksdb = { git = "https://github.com/rust-rocksdb/rust-rocksdb", rev = "1710120 # To switch to the local path, run: # scripts/tool/update_collab_source.sh # ⚠️⚠️⚠️️ -collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } -collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "6f98f054a8306a8791b65bf1825091ab3fe60166" } +collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } +collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "79e649061da9245d81b9114f3aaaf0064c265c97" } # Working directory: frontend # To update the commit ID, run: diff --git a/frontend/rust-lib/collab-integrate/src/collab_builder.rs b/frontend/rust-lib/collab-integrate/src/collab_builder.rs index e20ab74a31..3ed01436f8 100644 --- a/frontend/rust-lib/collab-integrate/src/collab_builder.rs +++ b/frontend/rust-lib/collab-integrate/src/collab_builder.rs @@ -8,7 +8,9 @@ use arc_swap::{ArcSwap, ArcSwapOption}; use collab::core::collab::DataSource; use collab::core::collab_plugin::CollabPersistence; use collab::preclude::{Collab, CollabBuilder}; -use collab_database::workspace_database::{DatabaseCollabService, WorkspaceDatabase}; +use collab_database::workspace_database::{ + DatabaseCollabCloudService, DatabaseCollabService, WorkspaceDatabase, +}; use collab_document::blocks::DocumentData; use collab_document::document::Document; use collab_entity::{CollabObject, CollabType}; @@ -236,10 +238,7 @@ impl AppFlowyCollabBuilder { } #[allow(clippy::too_many_arguments)] - #[instrument( - level = "trace", - skip(self, object, doc_state, collab_db, builder_config, collab_service) - )] + #[instrument(level = "trace", skip_all)] pub fn create_workspace_database( &self, object: CollabObject, @@ -247,11 +246,12 @@ impl AppFlowyCollabBuilder { collab_db: Weak, builder_config: CollabBuilderConfig, collab_service: impl DatabaseCollabService, + cloud_service: impl DatabaseCollabCloudService, ) -> Result>, Error> { let expected_collab_type = CollabType::WorkspaceDatabase; assert_eq!(object.collab_type, expected_collab_type); let collab = self.build_collab(&object, &collab_db, doc_state)?; - let workspace = WorkspaceDatabase::open(object.uid, collab, collab_service); + let workspace = WorkspaceDatabase::open(collab, collab_service, cloud_service); self.flush_collab_if_not_exist( object.uid, diff --git a/frontend/rust-lib/flowy-database2/src/manager.rs b/frontend/rust-lib/flowy-database2/src/manager.rs index 51626126bb..391c4b40c4 100644 --- a/frontend/rust-lib/flowy-database2/src/manager.rs +++ b/frontend/rust-lib/flowy-database2/src/manager.rs @@ -13,8 +13,8 @@ use collab_database::error::DatabaseError; use collab_database::rows::RowId; use collab_database::views::DatabaseLayout; use collab_database::workspace_database::{ - DatabaseCollabPersistenceService, DatabaseCollabService, DatabaseMeta, EncodeCollabByOid, - WorkspaceDatabase, + DatabaseCollabCloudService, DatabaseCollabPersistenceService, DatabaseCollabService, + DatabaseMeta, EncodeCollabByOid, WorkspaceDatabase, }; use collab_entity::{CollabType, EncodedCollab}; use collab_plugins::local_storage::kv::KVTransactionDB; @@ -107,9 +107,12 @@ impl DatabaseManager { } let collab_db = self.user.collab_db(uid)?; - let collab_builder = UserDatabaseCollabServiceImpl { + let collab_service = WorkspaceDatabaseCollabServiceImpl { user: self.user.clone(), collab_builder: self.collab_builder.clone(), + }; + let collab_cloud_service = WorkspaceDatabaseCloudServiceImpl { + user: self.user.clone(), cloud_service: self.cloud_service.clone(), }; @@ -167,7 +170,8 @@ impl DatabaseManager { workspace_database_data_source, collab_db, CollabBuilderConfig::default().sync_enable(true), - collab_builder, + collab_service, + collab_cloud_service, )?; self.workspace_database.store(Some(workspace_database)); Ok(()) @@ -673,14 +677,13 @@ impl DatabaseManager { } } -struct UserDatabaseCollabServiceImpl { +struct WorkspaceDatabaseCloudServiceImpl { user: Arc, - collab_builder: Arc, cloud_service: Arc, } #[async_trait] -impl DatabaseCollabService for UserDatabaseCollabServiceImpl { +impl DatabaseCollabCloudService for WorkspaceDatabaseCloudServiceImpl { async fn get_encode_collab( &self, object_id: &str, @@ -726,16 +729,27 @@ impl DatabaseCollabService for UserDatabaseCollabServiceImpl { }, } } +} +struct WorkspaceDatabaseCollabServiceImpl { + user: Arc, + collab_builder: Arc, +} + +#[async_trait] +impl DatabaseCollabService for WorkspaceDatabaseCollabServiceImpl { ///NOTE: this method doesn't initialize plugins, however it is passed into WorkspaceDatabase, /// therefore all Database/DatabaseRow creation methods must initialize plugins thmselves. fn build_collab( &self, - uid: i64, object_id: &str, object_type: CollabType, data_source: DataSource, ) -> Result { + let uid = self + .user + .user_id() + .map_err(|err| DatabaseError::Internal(err.into()))?; let workspace_id = self .user .workspace_id() @@ -765,8 +779,13 @@ pub struct DatabasePersistenceImpl { } impl DatabaseCollabPersistenceService for DatabasePersistenceImpl { - fn load_collab(&self, uid: i64, collab: &mut Collab) { - if let Ok(Some(collab_db)) = self.user.collab_db(uid).map(|weak| weak.upgrade()) { + fn load_collab(&self, collab: &mut Collab) { + let result = self + .user + .user_id() + .map(|uid| (uid, self.user.collab_db(uid).map(|weak| weak.upgrade()))); + + if let Ok((uid, Ok(Some(collab_db)))) = result { let object_id = collab.object_id().to_string(); let db_read = collab_db.read_txn(); if !db_read.is_exist(uid, &object_id) { @@ -795,7 +814,11 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl { } } - fn delete_collab(&self, uid: i64, object_id: &str) -> Result<(), DatabaseError> { + fn delete_collab(&self, object_id: &str) -> Result<(), DatabaseError> { + let uid = self + .user + .user_id() + .map_err(|err| DatabaseError::Internal(err.into()))?; if let Ok(Some(collab_db)) = self.user.collab_db(uid).map(|weak| weak.upgrade()) { let write_txn = collab_db.write_txn(); write_txn.delete_doc(uid, object_id).unwrap(); @@ -806,21 +829,33 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl { Ok(()) } - fn is_collab_exist(&self, uid: i64, object_id: &str) -> bool { - if let Ok(Some(collab_db)) = self.user.collab_db(uid).map(|weak| weak.upgrade()) { - let read_txn = collab_db.read_txn(); - return read_txn.is_exist(uid, object_id); + fn is_collab_exist(&self, object_id: &str) -> bool { + match self + .user + .user_id() + .map_err(|err| DatabaseError::Internal(err.into())) + { + Ok(uid) => { + if let Ok(Some(collab_db)) = self.user.collab_db(uid).map(|weak| weak.upgrade()) { + let read_txn = collab_db.read_txn(); + return read_txn.is_exist(uid, object_id); + } + false + }, + Err(_) => false, } - false } fn flush_collab( &self, - uid: i64, object_id: &str, encode_collab: EncodedCollab, ) -> Result<(), DatabaseError> { trace!("[Database]: flush collab:{}", object_id); + let uid = self + .user + .user_id() + .map_err(|err| DatabaseError::Internal(err.into()))?; if let Ok(Some(collab_db)) = self.user.collab_db(uid).map(|weak| weak.upgrade()) { let write_txn = collab_db.write_txn(); write_txn @@ -839,12 +874,14 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl { Ok(()) } - fn is_row_exist_partition(&self, uid: i64, row_ids: Vec) -> (Vec, Vec) { - if let Ok(Some(collab_db)) = self.user.collab_db(uid).map(|weak| weak.upgrade()) { - let read_txn = collab_db.read_txn(); - return row_ids - .into_iter() - .partition(|row_id| read_txn.is_exist(uid, row_id.as_ref())); + fn is_row_exist_partition(&self, row_ids: Vec) -> (Vec, Vec) { + if let Ok(uid) = self.user.user_id() { + if let Ok(Some(collab_db)) = self.user.collab_db(uid).map(|weak| weak.upgrade()) { + let read_txn = collab_db.read_txn(); + return row_ids + .into_iter() + .partition(|row_id| read_txn.is_exist(uid, row_id.as_ref())); + } } (vec![], row_ids)