Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: optimize import appflowy data (#6671)
Nathan.foooe6357a9d6cdd
diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.lock b/frontend/appflowy_tauri/src-tauri/Cargo.lockindex 8125aece02..05ad9bbf22 100644--- a/frontend/appflowy_tauri/src-tauri/Cargo.lock+++ b/frontend/appflowy_tauri/src-tauri/Cargo.lock@@ -1030,7 +1030,7 @@ dependencies = [[[package]]name = "collab"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","arc-swap",@@ -1055,7 +1055,7 @@ dependencies = [[[package]]name = "collab-database"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","async-trait",@@ -1094,7 +1094,7 @@ dependencies = [[[package]]name = "collab-document"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","arc-swap",@@ -1115,7 +1115,7 @@ dependencies = [[[package]]name = "collab-entity"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","bytes",@@ -1135,7 +1135,7 @@ dependencies = [[[package]]name = "collab-folder"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","arc-swap",@@ -1157,7 +1157,7 @@ dependencies = [[[package]]name = "collab-importer"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","async-recursion",@@ -1218,7 +1218,7 @@ dependencies = [[[package]]name = "collab-plugins"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","async-stream",@@ -1298,7 +1298,7 @@ dependencies = [[[package]]name = "collab-user"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","collab",diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.toml b/frontend/appflowy_tauri/src-tauri/Cargo.tomlindex 5e091e3f9d..4a525c6798 100644--- a/frontend/appflowy_tauri/src-tauri/Cargo.toml+++ b/frontend/appflowy_tauri/src-tauri/Cargo.toml@@ -120,14 +120,14 @@ 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 = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }+collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }# 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.lockindex a01f0b0d49..732c041a37 100644--- a/frontend/appflowy_web_app/src-tauri/Cargo.lock+++ b/frontend/appflowy_web_app/src-tauri/Cargo.lock@@ -1028,7 +1028,7 @@ dependencies = [[[package]]name = "collab"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","arc-swap",@@ -1053,7 +1053,7 @@ dependencies = [[[package]]name = "collab-database"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","async-trait",@@ -1092,7 +1092,7 @@ dependencies = [[[package]]name = "collab-document"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","arc-swap",@@ -1113,7 +1113,7 @@ dependencies = [[[package]]name = "collab-entity"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","bytes",@@ -1133,7 +1133,7 @@ dependencies = [[[package]]name = "collab-folder"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","arc-swap",@@ -1155,7 +1155,7 @@ dependencies = [[[package]]name = "collab-importer"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","async-recursion",@@ -1216,7 +1216,7 @@ dependencies = [[[package]]name = "collab-plugins"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","async-stream",@@ -1296,7 +1296,7 @@ dependencies = [[[package]]name = "collab-user"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","collab",diff --git a/frontend/appflowy_web_app/src-tauri/Cargo.toml b/frontend/appflowy_web_app/src-tauri/Cargo.tomlindex 4e4e18e690..64a30a8364 100644--- a/frontend/appflowy_web_app/src-tauri/Cargo.toml+++ b/frontend/appflowy_web_app/src-tauri/Cargo.toml@@ -118,14 +118,14 @@ 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 = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }+collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }# Working directory: frontenddiff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lockindex 1d42d9832b..bf6f1e47d3 100644--- a/frontend/rust-lib/Cargo.lock+++ b/frontend/rust-lib/Cargo.lock@@ -891,7 +891,7 @@ dependencies = [[[package]]name = "collab"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","arc-swap",@@ -916,7 +916,7 @@ dependencies = [[[package]]name = "collab-database"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","async-trait",@@ -955,7 +955,7 @@ dependencies = [[[package]]name = "collab-document"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","arc-swap",@@ -976,7 +976,7 @@ dependencies = [[[package]]name = "collab-entity"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","bytes",@@ -996,7 +996,7 @@ dependencies = [[[package]]name = "collab-folder"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","arc-swap",@@ -1018,7 +1018,7 @@ dependencies = [[[package]]name = "collab-importer"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","async-recursion",@@ -1079,7 +1079,7 @@ dependencies = [[[package]]name = "collab-plugins"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","async-stream",@@ -1159,7 +1159,7 @@ dependencies = [[[package]]name = "collab-user"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=ae51ebef5cfc9805d58e89adca2cff9ea6e0b730#ae51ebef5cfc9805d58e89adca2cff9ea6e0b730"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=60e4e8d642eb0fe5752bf917acbe2f66327b4b8d#60e4e8d642eb0fe5752bf917acbe2f66327b4b8d"dependencies = ["anyhow","collab",@@ -5520,6 +5520,9 @@ name = "semver"version = "1.0.23"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"+dependencies = [+ "serde",+][[package]]name = "serde"diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.tomlindex 5bb3a6d4ab..706a7dc746 100644--- a/frontend/rust-lib/Cargo.toml+++ b/frontend/rust-lib/Cargo.toml@@ -142,14 +142,14 @@ 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 = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }-collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "ae51ebef5cfc9805d58e89adca2cff9ea6e0b730" }+collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }+collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "60e4e8d642eb0fe5752bf917acbe2f66327b4b8d" }# 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.rsindex afe06b6cc3..acf6123076 100644--- a/frontend/rust-lib/collab-integrate/src/collab_builder.rs+++ b/frontend/rust-lib/collab-integrate/src/collab_builder.rs@@ -3,7 +3,7 @@ use std::fmt::{Debug, Display};use std::sync::{Arc, Weak};use crate::CollabKVDB;-use anyhow::Error;+use anyhow::{anyhow, Error};use arc_swap::{ArcSwap, ArcSwapOption};use collab::core::collab::DataSource;use collab::core::collab_plugin::CollabPersistence;@@ -169,6 +169,7 @@ impl AppFlowyCollabBuilder {let document = Document::create_with_data(collab, data)?;if let Err(err) = self.write_collab_to_disk(object.uid,+ &object.workspace_id,&object.object_id,collab_db.clone(),&object.collab_type,@@ -212,6 +213,7 @@ impl AppFlowyCollabBuilder {let folder = Folder::create(object.uid, collab, folder_notifier, data);if let Err(err) = self.write_collab_to_disk(object.uid,+ &object.workspace_id,&object.object_id,collab_db.clone(),&object.collab_type,@@ -277,6 +279,7 @@ impl AppFlowyCollabBuilder {let persistence_config = CollabPersistenceConfig::default();let db_plugin = RocksdbDiskPlugin::new_with_config(object.uid,+ object.workspace_id.clone(),object.object_id.to_string(),object.collab_type.clone(),collab_db.clone(),@@ -338,6 +341,7 @@ impl AppFlowyCollabBuilder {pub fn write_collab_to_disk<T>(&self,uid: i64,+ workspace_id: &str,object_id: &str,collab_db: Weak<CollabKVDB>,collab_type: &CollabType,@@ -354,6 +358,7 @@ impl AppFlowyCollabBuilder {collab.encode_collab_v1(|collab| collab_type.validate_require_data(collab))?;write_txn.flush_doc(uid,+ workspace_id,object_id,encode_collab.state_vector.to_vec(),encode_collab.doc_state.to_vec(),@@ -387,11 +392,16 @@ impl CollabBuilderConfig {pub struct CollabPersistenceImpl {pub db: Weak<CollabKVDB>,pub uid: i64,+ pub workspace_id: String,}impl CollabPersistenceImpl {- pub fn new(db: Weak<CollabKVDB>, uid: i64) -> Self {- Self { db, uid }+ pub fn new(db: Weak<CollabKVDB>, uid: i64, workspace_id: String) -> Self {+ Self {+ db,+ uid,+ workspace_id,+ }}pub fn into_data_source(self) -> DataSource {@@ -400,33 +410,35 @@ impl CollabPersistenceImpl {}impl CollabPersistence for CollabPersistenceImpl {- fn load_collab_from_disk(&self, collab: &mut Collab) {- if let Some(collab_db) = self.db.upgrade() {- let object_id = collab.object_id().to_string();- let rocksdb_read = collab_db.read_txn();-- if rocksdb_read.is_exist(self.uid, &object_id) {- let mut txn = collab.transact_mut();- match rocksdb_read.load_doc_with_txn(self.uid, &object_id, &mut txn) {- Ok(update_count) => {- trace!(- "did load collab:{}-{} from disk, update_count:{}",- self.uid,- object_id,- update_count- );- },- Err(err) => {- error!("🔴 load doc:{} failed: {}", object_id, err);- },- }- drop(rocksdb_read);- txn.commit();- drop(txn);+ fn load_collab_from_disk(&self, collab: &mut Collab) -> Result<(), CollabError> {+ let collab_db = self+ .db+ .upgrade()+ .ok_or_else(|| CollabError::Internal(anyhow!("collab_db is dropped")))?;++ let object_id = collab.object_id().to_string();+ let rocksdb_read = collab_db.read_txn();++ if rocksdb_read.is_exist(self.uid, &self.workspace_id, &object_id) {+ let mut txn = collab.transact_mut();+ match rocksdb_read.load_doc_with_txn(self.uid, &self.workspace_id, &object_id, &mut txn) {+ Ok(update_count) => {+ trace!(+ "did load collab:{}-{} from disk, update_count:{}",+ self.uid,+ object_id,+ update_count+ );+ },+ Err(err) => {+ error!("🔴 load doc:{} failed: {}", object_id, err);+ },}- } else {- warn!("collab_db is dropped");+ drop(rocksdb_read);+ txn.commit();+ drop(txn);}+ Ok(())}fn save_collab_to_disk(@@ -434,25 +446,24 @@ impl CollabPersistence for CollabPersistenceImpl {object_id: &str,encoded_collab: EncodedCollab,) -> Result<(), CollabError> {- if let Some(collab_db) = self.db.upgrade() {- let write_txn = collab_db.write_txn();- write_txn- .flush_doc(- self.uid,- object_id,- encoded_collab.state_vector.to_vec(),- encoded_collab.doc_state.to_vec(),- )- .map_err(|err| CollabError::Internal(err.into()))?;-- write_txn- .commit_transaction()- .map_err(|err| CollabError::Internal(err.into()))?;- Ok(())- } else {- Err(CollabError::Internal(anyhow::anyhow!(- "collab_db is dropped"- )))- }+ let collab_db = self+ .db+ .upgrade()+ .ok_or_else(|| CollabError::Internal(anyhow!("collab_db is dropped")))?;+ let write_txn = collab_db.write_txn();+ write_txn+ .flush_doc(+ self.uid,+ self.workspace_id.as_str(),+ object_id,+ encoded_collab.state_vector.to_vec(),+ encoded_collab.doc_state.to_vec(),+ )+ .map_err(|err| CollabError::Internal(err.into()))?;++ write_txn+ .commit_transaction()+ .map_err(|err| CollabError::Internal(err.into()))?;+ Ok(())}}diff --git a/frontend/rust-lib/flowy-core/Cargo.toml b/frontend/rust-lib/flowy-core/Cargo.tomlindex 529203c872..09fd59d071 100644--- a/frontend/rust-lib/flowy-core/Cargo.toml+++ b/frontend/rust-lib/flowy-core/Cargo.toml@@ -60,7 +60,7 @@ serde_repr.workspace = truefutures.workspace = truewalkdir = "2.4.0"sysinfo = "0.30.5"-semver = "1.0.22"+semver = { version = "1.0.22", features = ["serde"] }[features]profiling = ["console-subscriber", "tokio/tracing"]diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rsindex e286be4731..1f38d30473 100644--- a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs@@ -197,7 +197,7 @@ impl FolderOperationHandler for DocumentFolderOperation {) -> Result<EncodedCollabWrapper, FlowyError> {// get the collab_object_id for the document.// the collab_object_id for the document is the view_id.-+ let workspace_id = user.workspace_id()?;let uid = user.user_id().map_err(|e| e.with_context("unable to get the uid: {}"))?;@@ -214,9 +214,10 @@ impl FolderOperationHandler for DocumentFolderOperation {let collab_read_txn = collab_db.read_txn();// read the collab from the db- let collab = load_collab_by_object_id(uid, &collab_read_txn, view_id).map_err(|e| {- FlowyError::internal().with_context(format!("load document collab failed: {}", e))- })?;+ let collab =+ load_collab_by_object_id(uid, &collab_read_txn, &workspace_id, view_id).map_err(|e| {+ FlowyError::internal().with_context(format!("load document collab failed: {}", e))+ })?;let encoded_collab = collab// encode the collab and check the integrity of the collab@@ -313,6 +314,7 @@ impl FolderOperationHandler for DatabaseFolderOperation {user: Arc<dyn FolderUser>,view_id: &str,) -> Result<EncodedCollabWrapper, FlowyError> {+ let workspace_id = user.workspace_id()?;// get the collab_object_id for the database.//// the collab object_id for the database is not the view_id,@@ -350,9 +352,10 @@ impl FolderOperationHandler for DatabaseFolderOperation {tokio::task::spawn_blocking(move || {let collab_read_txn = collab_db.read_txn();- let database_collab = load_collab_by_object_id(uid, &collab_read_txn, &oid).map_err(|e| {- FlowyError::internal().with_context(format!("load database collab failed: {}", e))- })?;+ let database_collab = load_collab_by_object_id(uid, &collab_read_txn, &workspace_id, &oid)+ .map_err(|e| {+ FlowyError::internal().with_context(format!("load database collab failed: {}", e))+ })?;let database_encoded_collab = database_collab// encode the collab and check the integrity of the collab@@ -362,7 +365,7 @@ impl FolderOperationHandler for DatabaseFolderOperation {})?;let database_row_encoded_collabs =- load_collab_by_object_ids(uid, &collab_read_txn, &row_oids)+ load_collab_by_object_ids(uid, &workspace_id, &collab_read_txn, &row_oids).0.into_iter().map(|(oid, collab)| {@@ -388,7 +391,7 @@ impl FolderOperationHandler for DatabaseFolderOperation {.collect::<HashMap<_, _>>();let database_row_document_encoded_collabs =- load_collab_by_object_ids(uid, &collab_read_txn, &row_document_ids)+ load_collab_by_object_ids(uid, &workspace_id, &collab_read_txn, &row_document_ids).0.into_iter().map(|(oid, collab)| {diff --git a/frontend/rust-lib/flowy-database2/src/manager.rs b/frontend/rust-lib/flowy-database2/src/manager.rsindex 5ece2caa31..68c13b8e84 100644--- a/frontend/rust-lib/flowy-database2/src/manager.rs+++ b/frontend/rust-lib/flowy-database2/src/manager.rs@@ -918,9 +918,7 @@ impl DatabaseCollabService for WorkspaceDatabaseCollabServiceImpl {}fn persistence(&self) -> Option<Arc<dyn DatabaseCollabPersistenceService>> {- Some(Arc::new(DatabasePersistenceImpl {- user: self.user.clone(),- }))+ Some(self.persistence.clone())}}@@ -928,6 +926,16 @@ pub struct DatabasePersistenceImpl {user: Arc<dyn DatabaseUser>,}+impl DatabasePersistenceImpl {+ fn workspace_id(&self) -> Result<String, DatabaseError> {+ let workspace_id = self+ .user+ .workspace_id()+ .map_err(|err| DatabaseError::Internal(err.into()))?;+ Ok(workspace_id)+ }+}+impl DatabaseCollabPersistenceService for DatabasePersistenceImpl {fn load_collab(&self, collab: &mut Collab) {let result = self@@ -935,47 +943,50 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl {.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) {- trace!(- "[Database]: collab:{} not exist in local storage",- object_id- );- return;- }-- trace!("[Database]: start loading collab:{} from disk", object_id);- let mut txn = collab.transact_mut();- match db_read.load_doc_with_txn(uid, &object_id, &mut txn) {- Ok(update_count) => {+ if let Ok(workspace_id) = self.user.workspace_id() {+ 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, &workspace_id, &object_id) {trace!(- "[Database]: did load collab:{}, update_count:{}",- object_id,- update_count+ "[Database]: collab:{} not exist in local storage",+ object_id);- },- Err(err) => {- if !err.is_record_not_found() {- error!("[Database]: load collab:{} failed:{}", object_id, err);- }- },+ return;+ }++ trace!("[Database]: start loading collab:{} from disk", object_id);+ let mut txn = collab.transact_mut();+ match db_read.load_doc_with_txn(uid, &workspace_id, &object_id, &mut txn) {+ Ok(update_count) => {+ trace!(+ "[Database]: did load collab:{}, update_count:{}",+ object_id,+ update_count+ );+ },+ Err(err) => {+ if !err.is_record_not_found() {+ error!("[Database]: load collab:{} failed:{}", object_id, err);+ }+ },+ }}}}fn get_encoded_collab(&self, object_id: &str, collab_type: CollabType) -> Option<EncodedCollab> {+ let workspace_id = self.user.workspace_id().ok()?;let uid = self.user.user_id().ok()?;let db = self.user.collab_db(uid).ok()?.upgrade()?;let read_txn = db.read_txn();- if !read_txn.is_exist(uid, &object_id) {+ if !read_txn.is_exist(uid, workspace_id.as_str(), object_id) {return None;}let mut collab = Collab::new_with_origin(CollabOrigin::Empty, object_id, vec![], false);let mut txn = collab.transact_mut();- let _ = read_txn.load_doc_with_txn(uid, &object_id, &mut txn);+ let _ = read_txn.load_doc_with_txn(uid, workspace_id.as_str(), object_id, &mut txn);drop(txn);collab@@ -984,13 +995,16 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl {}fn delete_collab(&self, object_id: &str) -> Result<(), DatabaseError> {+ let workspace_id = self.workspace_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.delete_doc(uid, object_id).unwrap();+ write_txn+ .delete_doc(uid, workspace_id.as_str(), object_id)+ .unwrap();write_txn.commit_transaction().map_err(|err| DatabaseError::Internal(anyhow!("failed to commit transaction: {}", err)))?;@@ -1003,6 +1017,7 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl {object_id: &str,encoded_collab: EncodedCollab,) -> Result<(), DatabaseError> {+ let workspace_id = self.workspace_id()?;let uid = self.user.user_id()@@ -1012,6 +1027,7 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl {write_txn.flush_doc(uid,+ workspace_id.as_str(),object_id,encoded_collab.state_vector.to_vec(),encoded_collab.doc_state.to_vec(),@@ -1025,17 +1041,22 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl {}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);+ match self.user.workspace_id() {+ Ok(workspace_id) => {+ 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, workspace_id.as_str(), object_id);+ }+ false+ },+ Err(_) => false,}- false},Err(_) => false,}@@ -1049,12 +1070,18 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl {.user.user_id().map_err(|err| DatabaseError::Internal(err.into()))?;+ let workspace_id = self+ .user+ .workspace_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();for (object_id, encode_collab) in encoded_collabs {write_txn.flush_doc(uid,+ &workspace_id,&object_id,encode_collab.state_vector.to_vec(),encode_collab.doc_state.to_vec(),@@ -1067,19 +1094,6 @@ impl DatabaseCollabPersistenceService for DatabasePersistenceImpl {}Ok(())}-- fn is_row_exist_partition(&self, row_ids: Vec<RowId>) -> (Vec<RowId>, Vec<RowId>) {- 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)- }}async fn open_database_with_retry(workspace_database_manager: Arc<RwLock<WorkspaceDatabaseManager>>,diff --git a/frontend/rust-lib/flowy-document/src/manager.rs b/frontend/rust-lib/flowy-document/src/manager.rsindex 45054ea51c..6ef6c7aac2 100644--- a/frontend/rust-lib/flowy-document/src/manager.rs+++ b/frontend/rust-lib/flowy-document/src/manager.rs@@ -84,8 +84,10 @@ impl DocumentManager {/// Get the encoded collab of the document.pub fn get_encoded_collab_with_view_id(&self, doc_id: &str) -> FlowyResult<EncodedCollab> {let uid = self.user_service.user_id()?;+ let workspace_id = self.user_service.workspace_id()?;let doc_state =- CollabPersistenceImpl::new(self.user_service.collab_db(uid)?, uid).into_data_source();+ CollabPersistenceImpl::new(self.user_service.collab_db(uid)?, uid, workspace_id)+ .into_data_source();let collab = self.collab_for_document(uid, doc_id, doc_state, false)?;let encoded_collab = collab.try_read()@@ -123,8 +125,9 @@ impl DocumentManager {fn persistence(&self) -> FlowyResult<CollabPersistenceImpl> {let uid = self.user_service.user_id()?;+ let workspace_id = self.user_service.workspace_id()?;let db = self.user_service.collab_db(uid)?;- Ok(CollabPersistenceImpl::new(db, uid))+ Ok(CollabPersistenceImpl::new(db, uid, workspace_id))}/// Create a new document.@@ -333,8 +336,9 @@ impl DocumentManager {pub async fn delete_document(&self, doc_id: &str) -> FlowyResult<()> {let uid = self.user_service.user_id()?;+ let workspace_id = self.user_service.workspace_id()?;if let Some(db) = self.user_service.collab_db(uid)?.upgrade() {- db.delete_doc(uid, doc_id).await?;+ db.delete_doc(uid, &workspace_id, doc_id).await?;// When deleting a document, we need to remove it from the cache.self.documents.remove(doc_id);}@@ -426,8 +430,9 @@ impl DocumentManager {async fn is_doc_exist(&self, doc_id: &str) -> FlowyResult<bool> {let uid = self.user_service.user_id()?;+ let workspace_id = self.user_service.workspace_id()?;if let Some(collab_db) = self.user_service.collab_db(uid)?.upgrade() {- let is_exist = collab_db.is_exist(uid, doc_id).await?;+ let is_exist = collab_db.is_exist(uid, &workspace_id, doc_id).await?;Ok(is_exist)} else {Ok(false)diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rsindex 878f7e385a..ef943879a1 100644--- a/frontend/rust-lib/flowy-folder/src/manager.rs+++ b/frontend/rust-lib/flowy-folder/src/manager.rs@@ -158,8 +158,10 @@ impl FolderManager {// only need the check the workspace id when the doc state is not from the disk.let config = CollabBuilderConfig::default().sync_enable(true);- let data_source = data_source- .unwrap_or_else(|| CollabPersistenceImpl::new(collab_db.clone(), uid).into_data_source());+ let data_source = data_source.unwrap_or_else(|| {+ CollabPersistenceImpl::new(collab_db.clone(), uid, workspace_id.to_string())+ .into_data_source()+ });let object_id = workspace_id;let collab_object =@@ -186,7 +188,7 @@ impl FolderManager {err);if let Some(db) = self.user.collab_db(uid).ok().and_then(|a| a.upgrade()) {- let _ = db.delete_doc(uid, workspace_id).await;+ let _ = db.delete_doc(uid, workspace_id, workspace_id).await;}Err(err.into())},@@ -207,7 +209,8 @@ impl FolderManager {.collab_builder.collab_object(workspace_id, uid, object_id, CollabType::Folder)?;- let doc_state = CollabPersistenceImpl::new(collab_db.clone(), uid).into_data_source();+ let doc_state = CollabPersistenceImpl::new(collab_db.clone(), uid, workspace_id.to_string())+ .into_data_source();let folder = self.collab_builder.create_folder(collab_object,doc_state,diff --git a/frontend/rust-lib/flowy-user/src/anon_user/migrate_anon_user_collab.rs b/frontend/rust-lib/flowy-user/src/anon_user/migrate_anon_user_collab.rsdeleted file mode 100644index ae7d5329bf..0000000000--- a/frontend/rust-lib/flowy-user/src/anon_user/migrate_anon_user_collab.rs+++ /dev/null@@ -1,480 +0,0 @@-use std::collections::{HashMap, HashSet};-use std::ops::{Deref, DerefMut};-use std::sync::Arc;--use anyhow::anyhow;-use collab::core::collab::DataSource;-use collab::core::origin::{CollabClient, CollabOrigin};-use collab::preclude::Collab;-use collab_database::database::{- is_database_collab, mut_database_views_with_collab, reset_inline_view_id,-};-use collab_database::rows::{database_row_document_id_from_row_id, mut_row_with_collab, RowId};-use collab_database::workspace_database::DatabaseMetaList;-use collab_folder::{Folder, UserId};-use collab_plugins::local_storage::kv::KVTransactionDB;-use tracing::info;--use collab_integrate::{CollabKVAction, CollabKVDB, PersistenceError};-use flowy_error::{ErrorCode, FlowyError, FlowyResult};-use flowy_folder_pub::cloud::gen_view_id;--use crate::migrations::AnonUser;-use flowy_user_pub::session::Session;--/// Migration the collab objects of the old user to new user. Currently, it only happens when-/// the user is a local user and try to use AppFlowy cloud service.-pub fn migration_anon_user_on_sign_up(- old_user: &AnonUser,- old_collab_db: &Arc<CollabKVDB>,- new_user_session: &Session,- new_collab_db: &Arc<CollabKVDB>,-) -> FlowyResult<()> {- new_collab_db- .with_write_txn(|new_collab_w_txn| {- let old_collab_r_txn = old_collab_db.read_txn();- let mut old_to_new_id_map = OldToNewIdMap::new();-- migrate_user_awareness(&mut old_to_new_id_map, old_user, new_user_session)?;-- migrate_database_with_views_object(- &mut old_to_new_id_map,- old_user,- &old_collab_r_txn,- new_user_session,- new_collab_w_txn,- )?;-- let mut object_ids = old_collab_r_txn- .get_all_docs()- .map(|iter| iter.collect::<Vec<String>>())- .unwrap_or_default();-- // Migration of all objects except the folder and database_with_views- object_ids.retain(|id| {- id != &old_user.session.user_workspace.id- && id != &old_user.session.user_workspace.database_indexer_id- });-- info!("migrate collab objects: {:?}", object_ids.len());- let mut collab_by_oid = make_collab_by_oid(old_user, &old_collab_r_txn, &object_ids);- migrate_databases(- &mut old_to_new_id_map,- new_user_session,- new_collab_w_txn,- &mut object_ids,- &mut collab_by_oid,- )?;-- // Migrates the folder, replacing all existing view IDs with new ones.- // This function handles the process of migrating folder data between two users. As a part of this migration,- // all existing view IDs associated with the old user will be replaced by new IDs relevant to the new user.- migrate_workspace_folder(- &mut old_to_new_id_map,- old_user,- &old_collab_r_txn,- new_user_session,- new_collab_w_txn,- )?;-- // Migrate other collab objects- for object_id in &object_ids {- if let Some(collab) = collab_by_oid.get(object_id) {- let new_object_id = old_to_new_id_map.exchange_new_id(object_id);- tracing::debug!("migrate from: {}, to: {}", object_id, new_object_id,);- migrate_collab_object(- collab,- new_user_session.user_id,- &new_object_id,- new_collab_w_txn,- );- }- }-- Ok(())- })- .map_err(|err| FlowyError::new(ErrorCode::Internal, err))?;-- Ok(())-}--#[derive(Default)]-pub struct OldToNewIdMap(HashMap<String, String>);--impl OldToNewIdMap {- fn new() -> Self {- Self::default()- }- fn exchange_new_id(&mut self, old_id: &str) -> String {- let view_id = self- .0- .entry(old_id.to_string())- .or_insert(gen_view_id().to_string());- (*view_id).clone()- }-}--impl Deref for OldToNewIdMap {- type Target = HashMap<String, String>;-- fn deref(&self) -> &Self::Target {- &self.0- }-}--impl DerefMut for OldToNewIdMap {- fn deref_mut(&mut self) -> &mut Self::Target {- &mut self.0- }-}--fn migrate_database_with_views_object<'a, 'b, W, R>(- old_to_new_id_map: &mut OldToNewIdMap,- old_user: &AnonUser,- old_collab_r_txn: &R,- new_user_session: &Session,- new_collab_w_txn: &W,-) -> Result<(), PersistenceError>-where- 'a: 'b,- W: CollabKVAction<'a>,- R: CollabKVAction<'b>,- PersistenceError: From<W::Error>,- PersistenceError: From<R::Error>,-{- let mut database_with_views_collab = Collab::new(- old_user.session.user_id,- &old_user.session.user_workspace.database_indexer_id,- "phantom",- vec![],- false,- );- old_collab_r_txn.load_doc_with_txn(- old_user.session.user_id,- &old_user.session.user_workspace.database_indexer_id,- &mut database_with_views_collab.transact_mut(),- )?;-- let new_uid = new_user_session.user_id;- let new_object_id = &new_user_session.user_workspace.database_indexer_id;-- let array = DatabaseMetaList::new(&mut database_with_views_collab);- let mut txn = database_with_views_collab.transact_mut();- for database_meta in array.get_all_database_meta(&txn) {- array.update_database(&mut txn, &database_meta.database_id, |update| {- let new_linked_views = update- .linked_views- .iter()- .map(|view_id| old_to_new_id_map.exchange_new_id(view_id))- .collect();- update.database_id = old_to_new_id_map.exchange_new_id(&update.database_id);- update.linked_views = new_linked_views;- })- }-- if let Err(err) = new_collab_w_txn.create_new_doc(new_uid, new_object_id, &txn) {- tracing::error!("🔴migrate database storage failed: {:?}", err);- }- drop(txn);- Ok(())-}--fn migrate_collab_object<'a, W>(collab: &Collab, new_uid: i64, new_object_id: &str, w_txn: &'a W)-where- W: CollabKVAction<'a>,- PersistenceError: From<W::Error>,-{- let txn = collab.transact();- if let Err(err) = w_txn.create_new_doc(new_uid, &new_object_id, &txn) {- tracing::error!("🔴migrate collab failed: {:?}", err);- }-}--fn migrate_workspace_folder<'a, 'b, W, R>(- old_to_new_id_map: &mut OldToNewIdMap,- old_user: &AnonUser,- old_collab_r_txn: &R,- new_user_session: &Session,- new_collab_w_txn: &W,-) -> Result<(), PersistenceError>-where- 'a: 'b,- W: CollabKVAction<'a>,- R: CollabKVAction<'b>,- PersistenceError: From<W::Error>,- PersistenceError: From<R::Error>,-{- let old_uid = old_user.session.user_id;- let old_workspace_id = &old_user.session.user_workspace.id;- let new_uid = new_user_session.user_id;- let new_workspace_id = &new_user_session.user_workspace.id;-- let mut old_folder_collab = Collab::new(old_uid, old_workspace_id, "phantom", vec![], false);- old_collab_r_txn.load_doc_with_txn(- old_uid,- old_workspace_id,- &mut old_folder_collab.transact_mut(),- )?;- let old_user_id = UserId::from(old_uid);- let old_folder = Folder::open(old_user_id.clone(), old_folder_collab, None)- .map_err(|err| PersistenceError::InvalidData(err.to_string()))?;- let mut folder_data =- old_folder- .get_folder_data(old_workspace_id)- .ok_or(PersistenceError::Internal(anyhow!(- "Can't migrate the folder data"- )))?;-- if let Some(old_fav_map) = folder_data.favorites.remove(&old_user_id) {- let fav_map = old_fav_map- .into_iter()- .map(|mut item| {- let new_view_id = old_to_new_id_map.exchange_new_id(&item.id);- item.id = new_view_id;- item- })- .collect();- folder_data.favorites.insert(UserId::from(new_uid), fav_map);- }- if let Some(old_trash_map) = folder_data.trash.remove(&old_user_id) {- let trash_map = old_trash_map- .into_iter()- .map(|mut item| {- let new_view_id = old_to_new_id_map.exchange_new_id(&item.id);- item.id = new_view_id;- item- })- .collect();- folder_data.trash.insert(UserId::from(new_uid), trash_map);- }-- if let Some(old_recent_map) = folder_data.recent.remove(&old_user_id) {- let recent_map = old_recent_map- .into_iter()- .map(|mut item| {- let new_view_id = old_to_new_id_map.exchange_new_id(&item.id);- item.id = new_view_id;- item- })- .collect();- folder_data.recent.insert(UserId::from(new_uid), recent_map);- }-- old_to_new_id_map- .0- .insert(old_workspace_id.to_string(), new_workspace_id.to_string());-- // 1. Replace the workspace views id to new id- folder_data.workspace.id = new_workspace_id.clone();- folder_data- .workspace- .child_views- .iter_mut()- .for_each(|view_identifier| {- view_identifier.id = old_to_new_id_map.exchange_new_id(&view_identifier.id);- });-- folder_data.views.iter_mut().for_each(|view| {- // 2. replace the old parent view id of the view- view.parent_view_id = old_to_new_id_map.exchange_new_id(&view.parent_view_id);-- // 3. replace the old id of the view- view.id = old_to_new_id_map.exchange_new_id(&view.id);-- // 4. replace the old id of the children views- view.children.iter_mut().for_each(|view_identifier| {- view_identifier.id = old_to_new_id_map.exchange_new_id(&view_identifier.id);- });- });-- match old_to_new_id_map.get(&folder_data.current_view) {- Some(new_view_id) => {- folder_data.current_view = new_view_id.clone();- },- None => {- tracing::error!("🔴migrate folder: current view id not found");- folder_data.current_view = "".to_string();- },- }-- let origin = CollabOrigin::Client(CollabClient::new(new_uid, "phantom"));- let new_folder_collab =- Collab::new_with_source(origin, new_workspace_id, DataSource::Disk, vec![], false)- .map_err(|err| PersistenceError::Internal(err.into()))?;- let new_user_id = UserId::from(new_uid);- info!("migrated folder: {:?}", folder_data);- let folder = Folder::open_with(new_user_id, new_folder_collab, None, Some(folder_data));-- {- let txn = folder.transact();- if let Err(err) = new_collab_w_txn.create_new_doc(new_uid, new_workspace_id, &txn) {- tracing::error!("🔴migrate folder failed: {:?}", err);- }- }- Ok(())-}--fn migrate_user_awareness(- old_to_new_id_map: &mut OldToNewIdMap,- old_user: &AnonUser,- new_user_session: &Session,-) -> Result<(), PersistenceError> {- let old_uid = old_user.session.user_id;- let new_uid = new_user_session.user_id;- tracing::debug!("migrate user awareness from: {}, to: {}", old_uid, new_uid);- old_to_new_id_map.insert(old_uid.to_string(), new_uid.to_string());- Ok(())-}--fn migrate_databases<'a, W>(- old_to_new_id_map: &mut OldToNewIdMap,- new_user_session: &Session,- new_collab_w_txn: &'a W,- object_ids: &mut Vec<String>,- collab_by_oid: &mut HashMap<String, Collab>,-) -> Result<(), PersistenceError>-where- W: CollabKVAction<'a>,- PersistenceError: From<W::Error>,-{- // Migrate databases- let mut database_object_ids = vec![];- let mut imported_database_row_object_ids: HashMap<String, HashSet<String>> = HashMap::new();-- for object_id in object_ids.iter() {- if let Some(collab) = collab_by_oid.get_mut(object_id) {- if !is_database_collab(collab) {- continue;- }-- database_object_ids.push(object_id.clone());- reset_inline_view_id(collab, |old_inline_view_id| {- old_to_new_id_map.exchange_new_id(&old_inline_view_id)- });-- mut_database_views_with_collab(collab, |database_view| {- let old_database_id = database_view.database_id.clone();- let new_view_id = old_to_new_id_map.exchange_new_id(&database_view.id);- let new_database_id = old_to_new_id_map.exchange_new_id(&database_view.database_id);-- tracing::trace!(- "migrate database view id from: {}, to: {}",- database_view.id,- new_view_id,- );- tracing::trace!(- "migrate database view database id from: {}, to: {}",- database_view.database_id,- new_database_id,- );-- database_view.id = new_view_id;- database_view.database_id = new_database_id;- database_view.row_orders.iter_mut().for_each(|row_order| {- let old_row_id = String::from(row_order.id.clone());- let old_row_document_id = database_row_document_id_from_row_id(&old_row_id);- let new_row_id = old_to_new_id_map.exchange_new_id(&old_row_id);- let new_row_document_id = database_row_document_id_from_row_id(&new_row_id);- tracing::debug!("migrate row id: {} to {}", row_order.id, new_row_id);- tracing::debug!(- "migrate row document id: {} to {}",- old_row_document_id,- new_row_document_id- );- old_to_new_id_map.insert(old_row_document_id, new_row_document_id);-- row_order.id = RowId::from(new_row_id);- imported_database_row_object_ids- .entry(old_database_id.clone())- .or_default()- .insert(old_row_id);- });- });-- let new_object_id = old_to_new_id_map.exchange_new_id(object_id);- tracing::debug!(- "migrate database from: {}, to: {}",- object_id,- new_object_id,- );- migrate_collab_object(- collab,- new_user_session.user_id,- &new_object_id,- new_collab_w_txn,- );- }- }-- // remove the database object ids from the object ids- object_ids.retain(|id| !database_object_ids.contains(id));-- // remove database row object ids from the imported object ids- object_ids.retain(|id| {- !imported_database_row_object_ids- .values()- .flatten()- .any(|row_id| row_id == id)- });- for (database_id, imported_row_ids) in imported_database_row_object_ids {- for imported_row_id in imported_row_ids {- if let Some(imported_collab) = collab_by_oid.get_mut(&imported_row_id) {- let new_database_id = old_to_new_id_map.exchange_new_id(&database_id);- let new_row_id = old_to_new_id_map.exchange_new_id(&imported_row_id);- info!(- "import database row from: {}, to: {}",- imported_row_id, new_row_id,- );- mut_row_with_collab(imported_collab, |row_update| {- row_update.set_row_id(RowId::from(new_row_id.clone()), new_database_id.clone());- });- migrate_collab_object(- imported_collab,- new_user_session.user_id,- &new_row_id,- new_collab_w_txn,- );- }-- // imported_collab_by_oid contains all the collab object ids, including the row document collab object ids.- // So, if the id exist in the imported_collab_by_oid, it means the row document collab object is exist.- let imported_row_document_id = database_row_document_id_from_row_id(&imported_row_id);- if collab_by_oid.get(&imported_row_document_id).is_some() {- let _ = old_to_new_id_map.exchange_new_id(&imported_row_document_id);- }- }- }-- Ok(())-}--fn make_collab_by_oid<'a, R>(- old_user: &AnonUser,- old_collab_r_txn: &R,- object_ids: &[String],-) -> HashMap<String, Collab>-where- R: CollabKVAction<'a>,- PersistenceError: From<R::Error>,-{- let mut collab_by_oid = HashMap::new();- for object_id in object_ids {- let mut collab = Collab::new(- old_user.session.user_id,- object_id,- "migrate_device",- vec![],- false,- );- let mut txn = collab.transact_mut();- match old_collab_r_txn.load_doc_with_txn(old_user.session.user_id, &object_id, &mut txn) {- Ok(_) => {- drop(txn);- collab_by_oid.insert(object_id.clone(), collab);- },- Err(err) => tracing::error!("🔴Initialize migration collab failed: {:?} ", err),- };- }-- collab_by_oid-}diff --git a/frontend/rust-lib/flowy-user/src/anon_user/mod.rs b/frontend/rust-lib/flowy-user/src/anon_user/mod.rsdeleted file mode 100644index 8a65b6fa94..0000000000--- a/frontend/rust-lib/flowy-user/src/anon_user/mod.rs+++ /dev/null@@ -1,3 +0,0 @@-//pub use migrate_anon_user_collab::*;--//mod migrate_anon_user_collab;diff --git a/frontend/rust-lib/flowy-user/src/anon_user/sync_supabase_user_collab.rs b/frontend/rust-lib/flowy-user/src/anon_user/sync_supabase_user_collab.rsdeleted file mode 100644index 7e95d9887c..0000000000--- a/frontend/rust-lib/flowy-user/src/anon_user/sync_supabase_user_collab.rs+++ /dev/null@@ -1,357 +0,0 @@-use std::sync::Arc;--use anyhow::{anyhow, Error};-use collab::preclude::{Collab, ReadTxn, StateVector};-use collab_database::database::get_database_row_ids;-use collab_database::rows::database_row_document_id_from_row_id;-use collab_database::workspace_database::{DatabaseMeta, DatabaseMetaList};-use collab_entity::{CollabObject, CollabType};-use collab_folder::{Folder, View, ViewLayout};-use collab_plugins::local_storage::kv::KVTransactionDB;--use collab_integrate::{CollabKVAction, CollabKVDB, PersistenceError};-use flowy_error::FlowyResult;-use flowy_user_pub::cloud::UserCloudService;-use flowy_user_pub::session::Session;--#[tracing::instrument(level = "info", skip_all, err)]-pub async fn sync_supabase_user_data_to_cloud(- user_service: Arc<dyn UserCloudService>,- device_id: &str,- new_user_session: &Session,- collab_db: &Arc<CollabKVDB>,-) -> FlowyResult<()> {- let workspace_id = new_user_session.user_workspace.id.clone();- let uid = new_user_session.user_id;- let folder = sync_folder(- uid,- &workspace_id,- device_id,- collab_db,- user_service.clone(),- )- .await?;-- let database_records = sync_database_views(- uid,- &workspace_id,- device_id,- &new_user_session.user_workspace.database_indexer_id,- collab_db,- user_service.clone(),- )- .await;-- let views = folder.get_views_belong_to(&workspace_id);- for view in views {- let view_id = view.id.clone();- if let Err(err) = sync_view(- uid,- &folder,- database_records.clone(),- workspace_id.to_string(),- device_id.to_string(),- view,- collab_db.clone(),- user_service.clone(),- )- .await- {- tracing::error!("🔴sync {} failed: {:?}", view_id, err);- }- }- tokio::task::yield_now().await;- Ok(())-}--#[allow(clippy::too_many_arguments)]-async fn sync_view(- uid: i64,- folder: &Folder,- database_metas: Vec<Arc<DatabaseMeta>>,- workspace_id: String,- device_id: String,- view: Arc<View>,- collab_db: Arc<CollabKVDB>,- user_service: Arc<dyn UserCloudService>,-) -> Result<(), Error> {- let collab_type = collab_type_from_view_layout(&view.layout);- let object_id = object_id_from_view(&view, &database_metas)?;- tracing::debug!(- "sync view: {:?}:{} with object_id: {}",- view.layout,- view.id,- object_id- );-- let collab_object = CollabObject::new(- uid,- object_id,- collab_type,- workspace_id.to_string(),- device_id.clone(),- );-- match view.layout {- ViewLayout::Document => {- let doc_state = get_collab_doc_state(uid, &collab_object, &collab_db)?;- tracing::info!(- "sync object: {} with update: {}",- collab_object,- doc_state.len()- );- user_service- .create_collab_object(&collab_object, doc_state)- .await?;- },- ViewLayout::Grid | ViewLayout::Board | ViewLayout::Calendar => {- let (database_doc_state, row_ids) = get_database_doc_state(uid, &collab_object, &collab_db)?;- tracing::info!(- "sync object: {} with update: {}",- collab_object,- database_doc_state.len()- );- user_service- .create_collab_object(&collab_object, database_doc_state)- .await?;-- // sync database's row- for row_id in row_ids {- tracing::debug!("sync row: {}", row_id);- let document_id = database_row_document_id_from_row_id(&row_id);-- let database_row_collab_object = CollabObject::new(- uid,- row_id,- CollabType::DatabaseRow,- workspace_id.to_string(),- device_id.clone(),- );- let database_row_doc_state =- get_collab_doc_state(uid, &database_row_collab_object, &collab_db)?;- tracing::info!(- "sync object: {} with update: {}",- database_row_collab_object,- database_row_doc_state.len()- );-- let _ = user_service- .create_collab_object(&database_row_collab_object, database_row_doc_state)- .await;-- let database_row_document = CollabObject::new(- uid,- document_id,- CollabType::Document,- workspace_id.to_string(),- device_id.to_string(),- );- // sync document in the row if exist- if let Ok(document_doc_state) =- get_collab_doc_state(uid, &database_row_document, &collab_db)- {- tracing::info!(- "sync database row document: {} with update: {}",- database_row_document,- document_doc_state.len()- );- let _ = user_service- .create_collab_object(&database_row_document, document_doc_state)- .await;- }- }- },- ViewLayout::Chat => {},- }-- tokio::task::yield_now().await;-- let child_views = folder.get_views_belong_to(&view.id);- for child_view in child_views {- let cloned_child_view = child_view.clone();- if let Err(err) = Box::pin(sync_view(- uid,- folder,- database_metas.clone(),- workspace_id.clone(),- device_id.to_string(),- child_view,- collab_db.clone(),- user_service.clone(),- ))- .await- {- tracing::error!(- "🔴sync {:?}:{} failed: {:?}",- cloned_child_view.layout,- cloned_child_view.id,- err- )- }- tokio::task::yield_now().await;- }- Ok(())-}--fn get_collab_doc_state(- uid: i64,- collab_object: &CollabObject,- collab_db: &Arc<CollabKVDB>,-) -> Result<Vec<u8>, PersistenceError> {- let mut collab = Collab::new(uid, &collab_object.object_id, "phantom", vec![], false);- collab_db.read_txn().load_doc_with_txn(- uid,- &collab_object.object_id,- &mut collab.transact_mut(),- )?;- let doc_state = collab- .encode_collab_v1(|_| Ok::<(), PersistenceError>(()))?- .doc_state;- if doc_state.is_empty() {- return Err(PersistenceError::UnexpectedEmptyUpdates);- }-- Ok(doc_state.to_vec())-}--fn get_database_doc_state(- uid: i64,- collab_object: &CollabObject,- collab_db: &Arc<CollabKVDB>,-) -> Result<(Vec<u8>, Vec<String>), PersistenceError> {- let mut collab = Collab::new(uid, &collab_object.object_id, "phantom", vec![], false);- collab_db.read_txn().load_doc_with_txn(- uid,- &collab_object.object_id,- &mut collab.transact_mut(),- )?;-- let row_ids = get_database_row_ids(&collab).unwrap_or_default();- let doc_state = collab- .encode_collab_v1(|_| Ok::<(), PersistenceError>(()))?- .doc_state;- if doc_state.is_empty() {- return Err(PersistenceError::UnexpectedEmptyUpdates);- }-- Ok((doc_state.to_vec(), row_ids))-}--async fn sync_folder(- uid: i64,- workspace_id: &str,- device_id: &str,- collab_db: &Arc<CollabKVDB>,- user_service: Arc<dyn UserCloudService>,-) -> Result<Folder, Error> {- let (folder, update) = {- let mut collab = Collab::new(uid, workspace_id, "phantom", vec![], false);- // Use the temporary result to short the lifetime of the TransactionMut- collab_db- .read_txn()- .load_doc_with_txn(uid, workspace_id, &mut collab.transact_mut())?;- let doc_state = collab- .encode_collab_v1(|_| Ok::<(), PersistenceError>(()))?- .doc_state;- (Folder::open(uid, collab, None)?, doc_state)- };-- let collab_object = CollabObject::new(- uid,- workspace_id.to_string(),- CollabType::Folder,- workspace_id.to_string(),- device_id.to_string(),- );- tracing::info!(- "sync object: {} with update: {}",- collab_object,- update.len()- );- if let Err(err) = user_service- .create_collab_object(&collab_object, update.to_vec())- .await- {- tracing::error!("🔴sync folder failed: {:?}", err);- }-- Ok(folder)-}--async fn sync_database_views(- uid: i64,- workspace_id: &str,- device_id: &str,- database_views_aggregate_id: &str,- collab_db: &Arc<CollabKVDB>,- user_service: Arc<dyn UserCloudService>,-) -> Vec<Arc<DatabaseMeta>> {- let collab_object = CollabObject::new(- uid,- database_views_aggregate_id.to_string(),- CollabType::WorkspaceDatabase,- workspace_id.to_string(),- device_id.to_string(),- );-- // Use the temporary result to short the lifetime of the TransactionMut- let result = {- let mut collab = Collab::new(uid, database_views_aggregate_id, "phantom", vec![], false);- let meta_list = DatabaseMetaList::new(&mut collab);- let mut txn = collab.transact_mut();- collab_db- .read_txn()- .load_doc_with_txn(uid, database_views_aggregate_id, &mut txn)- .map(|_| {- let records = meta_list.get_all_database_meta(&txn);- let doc_state = txn.encode_state_as_update_v2(&StateVector::default());- (records, doc_state)- })- };- match result {- Ok((records, doc_state)) => {- if let Err(e) = user_service- .create_collab_object(&collab_object, doc_state)- .await- {- tracing::error!(- "sync database views failed to create collab object: {:?}",- e- );- }- records.into_iter().map(Arc::new).collect()- },- Err(e) => {- tracing::error!("load doc {} failed: {:?}", database_views_aggregate_id, e);- vec![]- },- }-}--fn collab_type_from_view_layout(view_layout: &ViewLayout) -> CollabType {- match view_layout {- ViewLayout::Document => CollabType::Document,- ViewLayout::Grid | ViewLayout::Board | ViewLayout::Calendar => CollabType::Database,- ViewLayout::Chat => CollabType::Unknown,- }-}--fn object_id_from_view(- view: &Arc<View>,- database_records: &[Arc<DatabaseMeta>],-) -> Result<String, Error> {- if view.layout.is_database() {- match database_records- .iter()- .find(|record| record.linked_views.contains(&view.id))- {- None => Err(anyhow!(- "🔴sync view: {} failed: no database for this view",- view.id- )),- Some(record) => Ok(record.database_id.clone()),- }- } else {- Ok(view.id.clone())- }-}diff --git a/frontend/rust-lib/flowy-user/src/event_handler.rs b/frontend/rust-lib/flowy-user/src/event_handler.rsindex c954fd288f..96b0bbb73a 100644--- a/frontend/rust-lib/flowy-user/src/event_handler.rs+++ b/frontend/rust-lib/flowy-user/src/event_handler.rs@@ -277,9 +277,13 @@ pub async fn import_appflowy_data_folder_handler(af_spawn(async move {let result = async {let manager = upgrade_manager(manager)?;- let imported_folder = prepare_import(&data.path, data.parent_view_id)- .map_err(|err| FlowyError::new(ErrorCode::AppFlowyDataFolderImportError, err.to_string()))?- .with_container_name(data.import_container_name);+ let imported_folder = prepare_import(+ &data.path,+ data.parent_view_id,+ &manager.authenticate_user.user_config.app_version,+ )+ .map_err(|err| FlowyError::new(ErrorCode::AppFlowyDataFolderImportError, err.to_string()))?+ .with_container_name(data.import_container_name);manager.perform_import(imported_folder).await?;Ok::<(), FlowyError>(())diff --git a/frontend/rust-lib/flowy-user/src/lib.rs b/frontend/rust-lib/flowy-user/src/lib.rsindex 08fd0a7ff8..9a456b01e5 100644--- a/frontend/rust-lib/flowy-user/src/lib.rs+++ b/frontend/rust-lib/flowy-user/src/lib.rs@@ -1,7 +1,6 @@#[macro_use]extern crate flowy_sqlite;-mod anon_user;pub mod entities;mod event_handler;pub mod event_map;diff --git a/frontend/rust-lib/flowy-user/src/migrations/doc_key_with_workspace.rs b/frontend/rust-lib/flowy-user/src/migrations/doc_key_with_workspace.rsnew file mode 100644index 0000000000..09490699b6--- /dev/null+++ b/frontend/rust-lib/flowy-user/src/migrations/doc_key_with_workspace.rs@@ -0,0 +1,50 @@+use std::sync::Arc;++use collab_plugins::local_storage::kv::doc::migrate_old_keys;+use collab_plugins::local_storage::kv::KVTransactionDB;+use semver::Version;+use tracing::{instrument, trace};++use collab_integrate::CollabKVDB;+use flowy_error::FlowyResult;+use flowy_user_pub::entities::Authenticator;++use crate::migrations::migration::UserDataMigration;+use flowy_user_pub::session::Session;++pub struct CollabDocKeyWithWorkspaceIdMigration;++impl UserDataMigration for CollabDocKeyWithWorkspaceIdMigration {+ fn name(&self) -> &str {+ "collab_doc_key_with_workspace_id"+ }++ fn run_when(&self, first_installed_version: &Option<Version>, _current_version: &Version) -> bool {+ match first_installed_version {+ None => {+ // The user's initial installed version is None if they were using an AppFlowy version+ // lower than 0.7.3 and then upgraded to the latest version.+ true+ },+ Some(version) => version < &Version::new(0, 7, 3),+ }+ }++ #[instrument(name = "CollabDocKeyWithWorkspaceIdMigration", skip_all, err)]+ fn run(+ &self,+ session: &Session,+ collab_db: &Arc<CollabKVDB>,+ _authenticator: &Authenticator,+ ) -> FlowyResult<()> {+ trace!(+ "migrate key with workspace id:{}",+ session.user_workspace.id+ );+ collab_db.with_write_txn(|txn| {+ migrate_old_keys(txn, &session.user_workspace.id)?;+ Ok(())+ })?;+ Ok(())+ }+}diff --git a/frontend/rust-lib/flowy-user/src/migrations/document_empty_content.rs b/frontend/rust-lib/flowy-user/src/migrations/document_empty_content.rsindex 4fc86487be..cc5ccf68a0 100644--- a/frontend/rust-lib/flowy-user/src/migrations/document_empty_content.rs+++ b/frontend/rust-lib/flowy-user/src/migrations/document_empty_content.rs@@ -25,8 +25,11 @@ impl UserDataMigration for HistoricalEmptyDocumentMigration {"historical_empty_document"}- fn applies_to_version(&self, _version: &Version) -> bool {- true+ fn run_when(&self, first_installed_version: &Option<Version>, _current_version: &Version) -> bool {+ match first_installed_version {+ None => true,+ Some(version) => version < &Version::new(0, 4, 0),+ }}#[instrument(name = "HistoricalEmptyDocumentMigration", skip_all, err)]@@ -44,8 +47,12 @@ impl UserDataMigration for HistoricalEmptyDocumentMigration {}collab_db.with_write_txn(|write_txn| {let origin = CollabOrigin::Client(CollabClient::new(session.user_id, "phantom"));- let folder_collab = match load_collab(session.user_id, write_txn, &session.user_workspace.id)- {+ let folder_collab = match load_collab(+ session.user_id,+ write_txn,+ &session.user_workspace.id,+ &session.user_workspace.id,+ ) {Ok(fc) => fc,Err(_) => return Ok(()),};@@ -57,7 +64,15 @@ impl UserDataMigration for HistoricalEmptyDocumentMigration {// For historical reasons, the first level documents are empty. So migrate them by inserting// the default document data.for view in migration_views {- if migrate_empty_document(write_txn, &origin, &view, session.user_id).is_err() {+ if migrate_empty_document(+ write_txn,+ &origin,+ &view,+ session.user_id,+ &session.user_workspace.id,+ )+ .is_err()+ {event!(tracing::Level::ERROR,"Failed to migrate document {}",@@ -79,18 +94,20 @@ fn migrate_empty_document<'a, W>(origin: &CollabOrigin,view: &View,user_id: i64,+ workspace_id: &str,) -> Result<(), FlowyError>whereW: CollabKVAction<'a>,PersistenceError: From<W::Error>,{// If the document is not exist, we don't need to migrate it.- if load_collab(user_id, write_txn, &view.id).is_err() {+ if load_collab(user_id, write_txn, workspace_id, &view.id).is_err() {let collab = Collab::new_with_origin(origin.clone(), &view.id, vec![], false);let document = Document::create_with_data(collab, default_document_data(&view.id))?;let encode = document.encode_collab_v1(|_| Ok::<(), PersistenceError>(()))?;write_txn.flush_doc(user_id,+ workspace_id,&view.id,encode.state_vector.to_vec(),encode.doc_state.to_vec(),diff --git a/frontend/rust-lib/flowy-user/src/migrations/migration.rs b/frontend/rust-lib/flowy-user/src/migrations/migration.rsindex 26be72707a..c604e47e8d 100644--- a/frontend/rust-lib/flowy-user/src/migrations/migration.rs+++ b/frontend/rust-lib/flowy-user/src/migrations/migration.rs@@ -1,21 +1,26 @@use std::sync::Arc;use chrono::NaiveDateTime;-use diesel::{RunQueryDsl, SqliteConnection};-use semver::Version;-use collab_integrate::CollabKVDB;+use diesel::{RunQueryDsl, SqliteConnection};use flowy_error::FlowyResult;+use flowy_sqlite::kv::KVStorePreferences;use flowy_sqlite::schema::user_data_migration_records;use flowy_sqlite::ConnectionPool;use flowy_user_pub::entities::Authenticator;-use flowy_user_pub::session::Session;+use semver::Version;+use tracing::info;++/// Store the version that user first time install AppFlowy. For old user, this value will be set+/// to the version when upgrade to the newest version.+pub const FIRST_TIME_INSTALL_VERSION: &str = "first_install_version";pub struct UserLocalDataMigration {session: Session,collab_db: Arc<CollabKVDB>,sqlite_pool: Arc<ConnectionPool>,+ kv: Arc<KVStorePreferences>,}impl UserLocalDataMigration {@@ -23,11 +28,13 @@ impl UserLocalDataMigration {session: Session,collab_db: Arc<CollabKVDB>,sqlite_pool: Arc<ConnectionPool>,+ kv: Arc<KVStorePreferences>,) -> Self {Self {session,collab_db,sqlite_pool,+ kv,}}@@ -48,21 +55,22 @@ impl UserLocalDataMigration {self,migrations: Vec<Box<dyn UserDataMigration>>,authenticator: &Authenticator,- app_version: Option<Version>,+ app_version: &Version,) -> FlowyResult<Vec<String>> {let mut applied_migrations = vec![];let mut conn = self.sqlite_pool.get()?;let record = get_all_records(&mut conn)?;+ let install_version = self.kv.get_object::<Version>(FIRST_TIME_INSTALL_VERSION);++ info!("[Migration] Install app version: {:?}", install_version);let mut duplicated_names = vec![];for migration in migrations {if !record.iter().any(|record| record.migration_name == migration.name()){- if let Some(app_version) = app_version.as_ref() {- if !migration.applies_to_version(app_version) {- continue;- }+ if !migration.run_when(&install_version, app_version) {+ continue;}let migration_name = migration.name().to_string();@@ -72,7 +80,7 @@ impl UserLocalDataMigration {save_migration_record(&mut conn, &migration_name);duplicated_names.push(migration_name);} else {- tracing::error!("Duplicated migration name: {}", migration_name);+ tracing::error!("[Migration] Duplicated migration name: {}", migration_name);}}}@@ -83,9 +91,9 @@ impl UserLocalDataMigration {pub trait UserDataMigration {/// Migration with the same name will be skippedfn name(&self) -> &str;- /// Returns bool value whether the migration should be applied to the current app version- /// true if the migration should be applied, false otherwise- fn applies_to_version(&self, app_version: &Version) -> bool;+ // The user's initial installed version is None if they were using an AppFlowy version lower than 0.7.3+ // Because we store the first time installed version after version 0.7.3.+ fn run_when(&self, first_installed_version: &Option<Version>, current_version: &Version) -> bool;fn run(&self,user: &Session,@@ -112,7 +120,7 @@ fn get_all_records(conn: &mut SqliteConnection) -> FlowyResult<Vec<UserDataMigra)}-#[derive(Clone, Default, Queryable, Identifiable)]+#[derive(Clone, Debug, Default, Queryable, Identifiable)]#[diesel(table_name = user_data_migration_records)]pub struct UserDataMigrationRecord {pub id: i32,diff --git a/frontend/rust-lib/flowy-user/src/migrations/mod.rs b/frontend/rust-lib/flowy-user/src/migrations/mod.rsindex bb43426e8a..c8d04edf66 100644--- a/frontend/rust-lib/flowy-user/src/migrations/mod.rs+++ b/frontend/rust-lib/flowy-user/src/migrations/mod.rs@@ -1,6 +1,7 @@use flowy_user_pub::session::Session;use std::sync::Arc;+pub mod doc_key_with_workspace;pub mod document_empty_content;pub mod migration;pub mod session_migration;diff --git a/frontend/rust-lib/flowy-user/src/migrations/util.rs b/frontend/rust-lib/flowy-user/src/migrations/util.rsindex f432ce05a6..9508228c6f 100644--- a/frontend/rust-lib/flowy-user/src/migrations/util.rs+++ b/frontend/rust-lib/flowy-user/src/migrations/util.rs@@ -3,12 +3,17 @@ use collab::preclude::Collab;use collab_integrate::{CollabKVAction, PersistenceError};use flowy_error::FlowyResult;-pub(crate) fn load_collab<'a, R>(uid: i64, collab_r_txn: &R, object_id: &str) -> FlowyResult<Collab>+pub(crate) fn load_collab<'a, R>(+ uid: i64,+ collab_r_txn: &R,+ workspace_id: &str,+ object_id: &str,+) -> FlowyResult<Collab>whereR: CollabKVAction<'a>,PersistenceError: From<R::Error>,{let mut collab = Collab::new(uid, object_id, "phantom", vec![], false);- collab_r_txn.load_doc_with_txn(uid, &object_id, &mut collab.transact_mut())?;+ collab_r_txn.load_doc_with_txn(uid, workspace_id, object_id, &mut collab.transact_mut())?;Ok(collab)}diff --git a/frontend/rust-lib/flowy-user/src/migrations/workspace_and_favorite_v1.rs b/frontend/rust-lib/flowy-user/src/migrations/workspace_and_favorite_v1.rsindex 2aaf3b8063..de55819f57 100644--- a/frontend/rust-lib/flowy-user/src/migrations/workspace_and_favorite_v1.rs+++ b/frontend/rust-lib/flowy-user/src/migrations/workspace_and_favorite_v1.rs@@ -23,8 +23,11 @@ impl UserDataMigration for FavoriteV1AndWorkspaceArrayMigration {"workspace_favorite_v1_and_workspace_array_migration"}- fn applies_to_version(&self, _app_version: &Version) -> bool {- true+ fn run_when(&self, first_installed_version: &Option<Version>, _current_version: &Version) -> bool {+ match first_installed_version {+ None => true,+ Some(version) => version < &Version::new(0, 4, 0),+ }}#[instrument(name = "FavoriteV1AndWorkspaceArrayMigration", skip_all, err)]@@ -35,7 +38,12 @@ impl UserDataMigration for FavoriteV1AndWorkspaceArrayMigration {_authenticator: &Authenticator,) -> FlowyResult<()> {collab_db.with_write_txn(|write_txn| {- if let Ok(collab) = load_collab(session.user_id, write_txn, &session.user_workspace.id) {+ if let Ok(collab) = load_collab(+ session.user_id,+ write_txn,+ &session.user_workspace.id,+ &session.user_workspace.id,+ ) {let mut folder = Folder::open(session.user_id, collab, None).map_err(|err| PersistenceError::Internal(err.into()))?;folder@@ -58,6 +66,7 @@ impl UserDataMigration for FavoriteV1AndWorkspaceArrayMigration {write_txn.flush_doc(session.user_id,&session.user_workspace.id,+ &session.user_workspace.id,encode.state_vector.to_vec(),encode.doc_state.to_vec(),)?;diff --git a/frontend/rust-lib/flowy-user/src/migrations/workspace_trash_v1.rs b/frontend/rust-lib/flowy-user/src/migrations/workspace_trash_v1.rsindex 47cecc35a0..623a0cbf64 100644--- a/frontend/rust-lib/flowy-user/src/migrations/workspace_trash_v1.rs+++ b/frontend/rust-lib/flowy-user/src/migrations/workspace_trash_v1.rs@@ -21,8 +21,11 @@ impl UserDataMigration for WorkspaceTrashMapToSectionMigration {"workspace_trash_map_to_section_migration"}- fn applies_to_version(&self, _app_version: &Version) -> bool {- true+ fn run_when(&self, first_installed_version: &Option<Version>, _current_version: &Version) -> bool {+ match first_installed_version {+ None => true,+ Some(version) => version < &Version::new(0, 4, 0),+ }}#[instrument(name = "WorkspaceTrashMapToSectionMigration", skip_all, err)]@@ -33,7 +36,12 @@ impl UserDataMigration for WorkspaceTrashMapToSectionMigration {_authenticator: &Authenticator,) -> FlowyResult<()> {collab_db.with_write_txn(|write_txn| {- if let Ok(collab) = load_collab(session.user_id, write_txn, &session.user_workspace.id) {+ if let Ok(collab) = load_collab(+ session.user_id,+ write_txn,+ &session.user_workspace.id,+ &session.user_workspace.id,+ ) {let mut folder = Folder::open(session.user_id, collab, None).map_err(|err| PersistenceError::Internal(err.into()))?;let trash_ids = folder@@ -52,6 +60,7 @@ impl UserDataMigration for WorkspaceTrashMapToSectionMigration {write_txn.flush_doc(session.user_id,&session.user_workspace.id,+ &session.user_workspace.id,encode.state_vector.to_vec(),encode.doc_state.to_vec(),)?;diff --git a/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs b/frontend/rust-lib/flowy-user/src/services/authenticate_user.rsindex dd122b16bc..14fc65ff9a 100644--- a/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs+++ b/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs@@ -4,6 +4,7 @@ use crate::services::entities::{UserConfig, UserPaths};use crate::services::sqlite_sql::user_sql::vacuum_database;use collab_integrate::CollabKVDB;+use arc_swap::ArcSwapOption;use collab_plugins::local_storage::kv::doc::CollabKVAction;use collab_plugins::local_storage::kv::KVTransactionDB;@@ -111,9 +112,10 @@ impl AuthenticateUser {}pub fn is_collab_on_disk(&self, uid: i64, object_id: &str) -> FlowyResult<bool> {+ let session = self.get_session()?;let collab_db = self.database.get_collab_db(uid)?;let read_txn = collab_db.read_txn();- Ok(read_txn.is_exist(uid, &object_id))+ Ok(read_txn.is_exist(uid, session.user_workspace.id.as_str(), object_id))}pub fn set_session(&self, session: Option<Arc<Session>>) -> Result<(), FlowyError> {diff --git a/frontend/rust-lib/flowy-user/src/services/data_import/appflowy_data_import.rs b/frontend/rust-lib/flowy-user/src/services/data_import/appflowy_data_import.rsindex f9657d45cf..8c334dc78b 100644--- a/frontend/rust-lib/flowy-user/src/services/data_import/appflowy_data_import.rs+++ b/frontend/rust-lib/flowy-user/src/services/data_import/appflowy_data_import.rs@@ -37,6 +37,7 @@ use std::collections::{HashMap, HashSet};use collab_document::blocks::TextDelta;use collab_document::document::Document;+use semver::Version;use serde_json::json;use std::ops::{Deref, DerefMut};use std::path::Path;@@ -66,6 +67,7 @@ impl ImportedFolder {pub(crate) fn prepare_import(path: &str,parent_view_id: Option<String>,+ app_version: &Version,) -> anyhow::Result<ImportedFolder> {info!("[AppflowyData]:importing data from path: {}, parent_view_id:{:?}",@@ -107,7 +109,8 @@ pub(crate) fn prepare_import(&imported_user,imported_collab_db.clone(),imported_sqlite_db.get_pool(),- None,+ other_store_preferences.clone(),+ app_version,);Ok(ImportedFolder {@@ -140,7 +143,6 @@ fn migrate_user_awareness(#[instrument(level = "debug", skip_all, err)]pub(crate) fn generate_import_data(current_session: &Session,- workspace_id: &str,user_collab_db: &Arc<CollabKVDB>,imported_folder: ImportedFolder,) -> anyhow::Result<ImportedAppFlowyData> {@@ -149,6 +151,8 @@ pub(crate) fn generate_import_data(imported_folder.imported_session.user_workspace.name,imported_folder.imported_session.user_workspace.id,);+ let workspace_id = current_session.user_workspace.id.clone();+ let imported_workspace_id = imported_folder.imported_session.user_workspace.id.clone();let imported_session = imported_folder.imported_session.clone();let imported_collab_db = imported_folder.imported_collab_db.clone();let imported_container_view_name = imported_folder.container_name.clone();@@ -176,11 +180,15 @@ pub(crate) fn generate_import_data(// 1. Get all the imported collab object idslet mut all_imported_object_ids = imported_collab_db_read_txn- .get_all_docs()+ .get_all_object_ids(imported_uid, imported_workspace_id.as_str()).map(|iter| iter.collect::<Vec<String>>()).unwrap_or_default();- info!("[AppflowyData]: {} has {} collab objects", imported_uid, all_imported_object_ids.len());+ info!(+ "[AppflowyData]: {} has {} collab objects",+ imported_uid,+ all_imported_object_ids.len()+ );// when doing import, we don't want to import these objects:// 1. user workspace@@ -218,6 +226,7 @@ pub(crate) fn generate_import_data(// 3. load imported collab objects data.let (mut imported_collab_by_oid, invalid_object_ids) = load_collab_by_object_ids(imported_session.user_id,+ &imported_workspace_id,&imported_collab_db_read_txn,&all_imported_object_ids,);@@ -235,8 +244,8 @@ pub(crate) fn generate_import_data(// import the databaselet MigrateDatabase {- database_view_ids ,- database_row_ids,+ database_view_ids,+ database_row_ids,} = migrate_databases(&mut old_to_new_id_map,current_session,@@ -275,42 +284,40 @@ pub(crate) fn generate_import_data(// Currently, when importing AppFlowy data, the view which is a space doesn't have a corresponding// collab data in disk.for view_id in not_exist_parent_view_ids {- if let Err(err) = create_empty_document_for_view(current_session.user_id, &view_id, current_collab_db_write_txn) {- error!("[AppflowyData]: create empty document for view failed: {}", err);+ if let Err(err) = create_empty_document_for_view(+ current_session.user_id,+ ¤t_session.user_workspace.id,+ &view_id,+ current_collab_db_write_txn,+ ) {+ error!(+ "[AppflowyData]: create empty document for view failed: {}",+ err+ );}}let gen_document_collabs = all_imported_object_ids- .par_iter()- .filter_map(|object_id| {- let f = || {- let imported_collab = imported_collab_by_oid.get(object_id)?;- let new_object_id = old_to_new_id_map.get_exchanged_id(object_id)?;- gen_sv_and_doc_state(- current_session.user_id,- new_object_id,- imported_collab,- CollabType::Document,- &old_to_new_id_map,- )- };- match f() {- None => {- warn!(- "[AppflowyData]: Can't find the new id for the imported object:{}, new object id:{:?}",- object_id,- old_to_new_id_map.get_exchanged_id(object_id),- );- None- },- Some(value) => Some(value),- }- })- .collect::<Vec<_>>();+ .par_iter()+ .filter_map(|object_id| {+ let f = || {+ let imported_collab = imported_collab_by_oid.get(object_id)?;+ let new_object_id = old_to_new_id_map.get_exchanged_id(object_id)?;+ gen_sv_and_doc_state(+ current_session.user_id,+ new_object_id,+ imported_collab,+ CollabType::Document,+ &old_to_new_id_map,+ )+ };+ f()+ })+ .collect::<Vec<_>>();for document_collab in gen_document_collabs {document_object_ids.insert(document_collab.object_id.clone());- write_gen_collab(document_collab, current_collab_db_write_txn);+ write_gen_collab(&workspace_id, document_collab, current_collab_db_write_txn);}let (mut views, orphan_views) = match imported_folder.source {@@ -388,6 +395,7 @@ pub(crate) fn generate_import_data(fn create_empty_document_for_view<'a, W>(uid: i64,+ workspace_id: &str,view_id: &str,collab_write_txn: &'a W,) -> FlowyResult<()>@@ -412,6 +420,7 @@ wherewrite_collab_object(&collab,uid,+ workspace_id,view_id,collab_write_txn,CollabType::Document,@@ -467,6 +476,7 @@ wherewrite_collab_object(&collab,current_session.user_id,+ current_session.user_workspace.id.as_str(),import_container_view_id,collab_write_txn,CollabType::Document,@@ -508,6 +518,7 @@ where);imported_collab_db_read_txn.load_doc_with_txn(imported_session.user_id,+ &imported_session.user_workspace.id,&imported_session.user_workspace.workspace_database_id,&mut workspace_database_collab.transact_mut(),)?;@@ -637,6 +648,7 @@ wherewrite_collab_object(database_collab,session.user_id,+ session.user_workspace.id.as_str(),&new_database_object_id,collab_write_txn,CollabType::Database,@@ -659,7 +671,7 @@ where}).collect::<Vec<_>>();for gen_collab in gen_database_row_document_collabs {- write_gen_collab(gen_collab, collab_write_txn);+ write_gen_collab(&session.user_workspace.id, gen_collab, collab_write_txn);}// remove the database object ids from the object ids@@ -746,7 +758,7 @@ where.collect::<Vec<_>>();for gen_collab in gen_database_row_collabs {- write_gen_collab(gen_collab, collab_write_txn);+ write_gen_collab(&session.user_workspace.id, gen_collab, collab_write_txn);}}@@ -756,6 +768,7 @@ wherefn write_collab_object<'a, W>(collab: &Collab,new_uid: i64,+ new_workspace_id: &str,new_object_id: &str,w_txn: &'a W,collab_type: CollabType,@@ -784,9 +797,13 @@ fn write_collab_object<'a, W>(let txn = doc.transact();let state_vector = txn.state_vector();let doc_state = txn.encode_state_as_update_v1(&StateVector::default());- if let Err(err) =- w_txn.flush_doc(new_uid, &new_object_id, state_vector.encode_v1(), doc_state)- {+ if let Err(err) = w_txn.flush_doc(+ new_uid,+ new_workspace_id,+ new_object_id,+ state_vector.encode_v1(),+ doc_state,+ ) {error!("[AppflowyData]:import collab:{} failed: {:?}",new_object_id, err@@ -805,12 +822,18 @@ struct GenCollab {object_id: String,}-fn write_gen_collab<'a, W>(collab: GenCollab, w_txn: &'a W)+fn write_gen_collab<'a, W>(workspace_id: &str, collab: GenCollab, w_txn: &'a W)whereW: CollabKVAction<'a>,PersistenceError: From<W::Error>,{- if let Err(err) = w_txn.flush_doc(collab.uid, &collab.object_id, collab.sv, collab.doc_state) {+ if let Err(err) = w_txn.flush_doc(+ collab.uid,+ workspace_id,+ collab.object_id.as_str(),+ collab.sv,+ collab.doc_state,+ ) {error!("[AppflowyData]:import collab:{} failed: {:?}",collab.object_id, err@@ -910,6 +933,7 @@ where.load_doc_with_txn(imported_session.user_id,&imported_session.user_workspace.id,+ &imported_session.user_workspace.id,&mut imported_folder_collab.transact_mut(),).map_err(|err| {@@ -1112,7 +1136,6 @@ impl OldToNewIdMap {Self::default()}fn exchange_new_id(&mut self, old_id: &str) -> String {- println!("old_id: {}", old_id);let view_id = self.0.entry(old_id.to_string())@@ -1159,6 +1182,7 @@ pub async fn upload_collab_objects_data(database_object_ids,} = collab_data;{+ let cloned_workspace_id = workspace_id.to_string();let object_by_collab_type = tokio::task::spawn_blocking(move || {let user_collab_db = user_collab_db.upgrade().ok_or_else(|| {FlowyError::internal().with_context(@@ -1175,7 +1199,12 @@ pub async fn upload_collab_objects_data();object_by_collab_type.insert(CollabType::Database,- load_and_process_collab_data(uid, &collab_read, &database_object_ids),+ load_and_process_collab_data(+ uid,+ &cloned_workspace_id,+ &collab_read,+ &database_object_ids,+ ),);event!(@@ -1184,7 +1213,12 @@ pub async fn upload_collab_objects_data();object_by_collab_type.insert(CollabType::Document,- load_and_process_collab_data(uid, &collab_read, &document_object_ids),+ load_and_process_collab_data(+ uid,+ &cloned_workspace_id,+ &collab_read,+ &document_object_ids,+ ),);event!(@@ -1193,7 +1227,7 @@ pub async fn upload_collab_objects_data();object_by_collab_type.insert(CollabType::DatabaseRow,- load_and_process_collab_data(uid, &collab_read, &row_object_ids),+ load_and_process_collab_data(uid, &cloned_workspace_id, &collab_read, &row_object_ids),);Ok::<_, FlowyError>(object_by_collab_type)})@@ -1262,6 +1296,7 @@ async fn batch_create(#[instrument(level = "debug", skip_all)]fn load_and_process_collab_data<'a, R>(uid: i64,+ workspace_id: &str,collab_read: &R,object_ids: &[String],) -> HashMap<String, Vec<u8>>@@ -1269,7 +1304,7 @@ whereR: CollabKVAction<'a>,PersistenceError: From<R::Error>,{- load_collab_by_object_ids(uid, collab_read, object_ids)+ load_collab_by_object_ids(uid, workspace_id, collab_read, object_ids).0.into_iter().filter_map(|(oid, collab)| {diff --git a/frontend/rust-lib/flowy-user/src/services/data_import/importer.rs b/frontend/rust-lib/flowy-user/src/services/data_import/importer.rsindex 76895033b1..3f01934ab7 100644--- a/frontend/rust-lib/flowy-user/src/services/data_import/importer.rs+++ b/frontend/rust-lib/flowy-user/src/services/data_import/importer.rs@@ -5,6 +5,7 @@ use std::collections::HashMap;/// This function loads collab objects by their object_ids.pub fn load_collab_by_object_ids<'a, R>(uid: i64,+ workspace_id: &str,collab_read_txn: &R,object_ids: &[String],) -> (HashMap<String, Collab>, Vec<String>)@@ -15,7 +16,7 @@ wherelet mut invalid_object_ids = vec![];let mut collab_by_oid = HashMap::new();for object_id in object_ids {- match load_collab_by_object_id(uid, collab_read_txn, object_id) {+ match load_collab_by_object_id(uid, collab_read_txn, workspace_id, object_id) {Ok(collab) => {collab_by_oid.insert(object_id.clone(), collab);},@@ -33,6 +34,7 @@ wherepub fn load_collab_by_object_id<'a, R>(uid: i64,collab_read_txn: &R,+ workspace_id: &str,object_id: &str,) -> Result<Collab, PersistenceError>where@@ -40,6 +42,6 @@ wherePersistenceError: From<R::Error>,{let mut collab = Collab::new(uid, object_id, "phantom", vec![], false);- collab_read_txn.load_doc_with_txn(uid, object_id, &mut collab.transact_mut())?;+ collab_read_txn.load_doc_with_txn(uid, workspace_id, object_id, &mut collab.transact_mut())?;Ok(collab)}diff --git a/frontend/rust-lib/flowy-user/src/services/db.rs b/frontend/rust-lib/flowy-user/src/services/db.rsindex 1050902f2b..97d8f865e6 100644--- a/frontend/rust-lib/flowy-user/src/services/db.rs+++ b/frontend/rust-lib/flowy-user/src/services/db.rs@@ -360,7 +360,7 @@ pub(crate) fn validate_collab_db(match result {Ok(db) => {let read_txn = db.read_txn();- read_txn.is_exist(uid, workspace_id)+ read_txn.is_exist(uid, workspace_id, workspace_id)},Err(err) => {error!("open collab db error, {:?}", err);diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager.rsindex 97621f60c0..a76c32f598 100644--- a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs@@ -21,7 +21,7 @@ use std::sync::atomic::{AtomicI64, Ordering};use std::sync::{Arc, Weak};use tokio::sync::Mutex;use tokio_stream::StreamExt;-use tracing::{debug, error, event, info, instrument, trace, warn};+use tracing::{debug, error, event, info, instrument, warn};use lib_dispatch::prelude::af_spawn;use lib_infra::box_any::BoxAny;@@ -30,7 +30,7 @@ use crate::entities::{AuthStateChangedPB, AuthStatePB, UserProfilePB, UserSettinuse crate::event_map::{DefaultUserStatusCallback, UserStatusCallback};use crate::migrations::document_empty_content::HistoricalEmptyDocumentMigration;use crate::migrations::migration::{- save_migration_record, UserDataMigration, UserLocalDataMigration,+ save_migration_record, UserDataMigration, UserLocalDataMigration, FIRST_TIME_INSTALL_VERSION,};use crate::migrations::workspace_and_favorite_v1::FavoriteV1AndWorkspaceArrayMigration;use crate::migrations::workspace_trash_v1::WorkspaceTrashMapToSectionMigration;@@ -39,6 +39,8 @@ use crate::services::authenticate_user::AuthenticateUser;use crate::services::cloud_config::get_cloud_config;use crate::services::collab_interact::{CollabInteract, DefaultCollabInteract};+use super::manager_user_workspace::save_user_workspace;+use crate::migrations::doc_key_with_workspace::CollabDocKeyWithWorkspaceIdMigration;use crate::services::sqlite_sql::user_sql::{select_user_profile, UserTable, UserTableChangeset};use crate::user_manager::manager_user_encryption::validate_encryption_sign;use crate::user_manager::manager_user_workspace::save_all_user_workspaces;@@ -46,8 +48,6 @@ use crate::user_manager::user_login_state::UserAuthProcess;use crate::{errors::FlowyError, notification::*};use flowy_user_pub::session::Session;-use super::manager_user_workspace::save_user_workspace;-pub struct UserManager {pub(crate) cloud_services: Arc<dyn UserCloudServiceProvider>,pub(crate) store_preferences: Arc<KVStorePreferences>,@@ -247,7 +247,7 @@ impl UserManager {}}- // Do the user data migration if needed+ // Do the user data migration if needed.event!(tracing::Level::INFO, "Prepare user data migration");match (self@@ -262,12 +262,16 @@ impl UserManager {&user,collab_db,sqlite_pool,- Some(self.authenticate_user.user_config.app_version.clone()),+ self.store_preferences.clone(),+ &self.authenticate_user.user_config.app_version,);},_ => error!("Failed to get collab db or sqlite pool"),}self.authenticate_user.vacuum_database_if_need();++ // migrations should run before set the first time installed version+ self.set_first_time_installed_version();let cloud_config = get_cloud_config(session.user_id, &self.store_preferences);// Init the user awareness. here we ignore the errorlet _ = self@@ -284,10 +288,31 @@ impl UserManager {&user.authenticator,).await?;+ } else {+ self.set_first_time_installed_version();}Ok(())}+ fn set_first_time_installed_version(&self) {+ if self+ .store_preferences+ .get_str(FIRST_TIME_INSTALL_VERSION)+ .is_none()+ {+ info!(+ "Set install version: {:?}",+ self.authenticate_user.user_config.app_version+ );+ if let Err(err) = self.store_preferences.set_object(+ FIRST_TIME_INSTALL_VERSION,+ &self.authenticate_user.user_config.app_version,+ ) {+ error!("Set install version error: {:?}", err);+ }+ }+ }+pub fn get_session(&self) -> FlowyResult<Arc<Session>> {self.authenticate_user.get_session()}@@ -854,6 +879,7 @@ fn collab_migration_list() -> Vec<Box<dyn UserDataMigration>> {Box::new(HistoricalEmptyDocumentMigration),Box::new(FavoriteV1AndWorkspaceArrayMigration),Box::new(WorkspaceTrashMapToSectionMigration),+ Box::new(CollabDocKeyWithWorkspaceIdMigration),]}@@ -871,19 +897,19 @@ pub(crate) fn run_collab_data_migration(user: &UserProfile,collab_db: Arc<CollabKVDB>,sqlite_pool: Arc<ConnectionPool>,- version: Option<Version>,+ kv: Arc<KVStorePreferences>,+ app_version: &Version,) {- trace!("[AppflowyData]:Run collab data migration: {:?}", version);let migrations = collab_migration_list();- match UserLocalDataMigration::new(session.clone(), collab_db, sqlite_pool).run(+ match UserLocalDataMigration::new(session.clone(), collab_db, sqlite_pool, kv).run(migrations,&user.authenticator,- version,+ app_version,) {Ok(applied_migrations) => {if !applied_migrations.is_empty() {info!(- "[AppflowyData]:Did apply migrations: {:?}",+ "[Migration]: did apply migrations: {:?}",applied_migrations);}diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_awareness.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_awareness.rsindex d982e4f7b9..0cfee15a16 100644--- a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_awareness.rs+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_awareness.rs@@ -156,8 +156,12 @@ impl UserManager {authenticator);let collab_db = self.get_collab_db(session.user_id)?;- let doc_state =- CollabPersistenceImpl::new(collab_db.clone(), session.user_id).into_data_source();+ let doc_state = CollabPersistenceImpl::new(+ collab_db.clone(),+ session.user_id,+ session.user_workspace.id.clone(),+ )+ .into_data_source();let awareness = Self::collab_for_user_awareness(&self.collab_builder.clone(),&session.user_workspace.id,@@ -219,8 +223,12 @@ impl UserManager {};let create_awareness = if authenticator.is_local() {- let doc_state =- CollabPersistenceImpl::new(collab_db.clone(), session.user_id).into_data_source();+ let doc_state = CollabPersistenceImpl::new(+ collab_db.clone(),+ session.user_id,+ session.user_workspace.id.clone(),+ )+ .into_data_source();Self::collab_for_user_awareness(&weak_builder,&session.user_workspace.id,@@ -252,8 +260,12 @@ impl UserManager {Err(err) => {if err.is_record_not_found() {info!("User awareness not found, creating new");- let doc_state =- CollabPersistenceImpl::new(collab_db.clone(), session.user_id).into_data_source();+ let doc_state = CollabPersistenceImpl::new(+ collab_db.clone(),+ session.user_id,+ session.user_workspace.id.clone(),+ )+ .into_data_source();Self::collab_for_user_awareness(&weak_builder,&session.user_workspace.id,diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rsindex 7f177b380e..7a779ecabd 100644--- a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs@@ -53,13 +53,8 @@ impl UserManager {let cloned_current_session = current_session.clone();let import_data = tokio::task::spawn_blocking(move || {- generate_import_data(- &cloned_current_session,- &cloned_current_session.user_workspace.id,- &user_collab_db,- imported_folder,- )- .map_err(|err| FlowyError::new(ErrorCode::AppFlowyDataFolderImportError, err.to_string()))+ generate_import_data(&cloned_current_session, &user_collab_db, imported_folder)+ .map_err(|err| FlowyError::new(ErrorCode::AppFlowyDataFolderImportError, err.to_string()))}).await??;