Prechádzať zdrojové kódy

chore: update workspace id from nanoid to uuid (#2731)

* chore: update workspace id

* ci: enable RUST_BACKTRACE

* chore: update patch
Nathan.fooo 1 rok pred
rodič
commit
3e3bdb59ae

+ 4 - 4
.github/workflows/rust_ci.yaml

@@ -65,6 +65,10 @@ jobs:
         run: |
           cargo make --profile development-linux-x86_64 appflowy-core-dev
 
+      - name: Run rust-lib tests
+        working-directory: frontend/rust-lib
+        run: RUST_LOG=info RUST_BACKTRACE=1 cargo test --no-default-features --features="rev-sqlite"
+
       - name: rustfmt rust-lib
         run: cargo fmt --all -- --check
         working-directory: frontend/rust-lib/
@@ -73,10 +77,6 @@ jobs:
         run: cargo clippy --features="rev-sqlite"
         working-directory: frontend/rust-lib
 
-      - name: Run rust-lib tests
-        working-directory: frontend/rust-lib
-        run: RUST_LOG=info cargo test --no-default-features --features="rev-sqlite"
-
       - name: rustfmt shared-lib
         run: cargo fmt --all -- --check
         working-directory: shared-lib

+ 1 - 1
frontend/.vscode/launch.json

@@ -13,7 +13,7 @@
             "preLaunchTask": "AF: Build Appflowy Core",
             "env": {
                 "RUST_LOG": "trace",
-                "RUST_BACKTRACE": 1,
+                "RUST_BACKTRACE": 1
             },
             "cwd": "${workspaceRoot}/appflowy_flutter"
         },

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

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

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

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

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

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

+ 21 - 6
frontend/rust-lib/flowy-folder2/src/manager.rs

@@ -64,13 +64,27 @@ impl Folder2Manager {
 
   pub async fn get_current_workspace(&self) -> FlowyResult<WorkspacePB> {
     self.with_folder(Err(FlowyError::internal()), |folder| {
+      let workspace_pb_from_workspace = |workspace: Workspace, folder: &Folder| {
+        let views = get_workspace_view_pbs(&workspace.id, folder);
+        let workspace: WorkspacePB = (workspace.clone(), views).into();
+        Ok::<WorkspacePB, FlowyError>(workspace)
+      };
+
       match folder.get_current_workspace() {
-        None => Err(FlowyError::record_not_found().context("Can not find the workspace")),
-        Some(workspace) => {
-          let views = get_workspace_view_pbs(&workspace.id, folder);
-          let workspace: WorkspacePB = (workspace, views).into();
-          Ok(workspace)
+        None => {
+          // The current workspace should always exist. If not, try to find the first workspace.
+          // from the folder. Otherwise, return an error.
+          let mut workspaces = folder.workspaces.get_all_workspaces();
+          if workspaces.is_empty() {
+            Err(FlowyError::record_not_found().context("Can not find the workspace"))
+          } else {
+            tracing::error!("Can't find the current workspace, use the first workspace");
+            let workspace = workspaces.remove(0);
+            folder.set_current_workspace(&workspace.id);
+            workspace_pb_from_workspace(workspace, folder)
+          }
         },
+        Some(workspace) => workspace_pb_from_workspace(workspace, folder),
       }
     })
   }
@@ -167,6 +181,7 @@ impl Folder2Manager {
       .cloud_service
       .create_workspace(self.user.user_id()?, &params.name)
       .await?;
+
     self.with_folder((), |folder| {
       folder.workspaces.create_workspace(workspace.clone());
       folder.set_current_workspace(&workspace.id);
@@ -187,7 +202,7 @@ impl Folder2Manager {
         .ok_or_else(|| {
           FlowyError::record_not_found().context("Can't open not existing workspace")
         })?;
-      folder.set_current_workspace(workspace_id);
+      folder.set_current_workspace(&workspace.id);
       Ok::<Workspace, FlowyError>(workspace)
     })
   }

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

@@ -1,7 +1,6 @@
 use std::sync::Arc;
 
 use collab_folder::core::{FolderData, RepeatedView, ViewIdentifier, Workspace};
-use nanoid::nanoid;
 use tokio::sync::RwLock;
 
 use lib_infra::util::timestamp;
@@ -73,7 +72,7 @@ impl DefaultFolderBuilder {
 }
 
 pub fn gen_workspace_id() -> String {
-  nanoid!(10)
+  uuid::Uuid::new_v4().to_string()
 }
 
 impl From<&ParentChildViews> for ViewPB {

+ 1 - 1
frontend/scripts/makefile/tests.toml

@@ -44,7 +44,7 @@ env = { RUST_LOG = "info" }
 description = "Run rust-lib unit tests"
 script = '''
 cd rust-lib
-cargo test --no-default-features --features="rev-sqlite"
+RUST_LOG=info RUST_BACKTRACE=1 cargo test --no-default-features --features="rev-sqlite"
 '''
 
 [tasks.shared_lib_unit_test]