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

* chore: update workspace id

* ci: enable RUST_BACKTRACE

* chore: update patch
This commit is contained in:
Nathan.fooo 2023-06-07 22:27:13 +08:00 committed by GitHub
parent 95d620931f
commit 3e3bdb59ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 35 deletions

View File

@ -65,6 +65,10 @@ jobs:
run: | run: |
cargo make --profile development-linux-x86_64 appflowy-core-dev 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 - name: rustfmt rust-lib
run: cargo fmt --all -- --check run: cargo fmt --all -- --check
working-directory: frontend/rust-lib/ working-directory: frontend/rust-lib/
@ -73,10 +77,6 @@ jobs:
run: cargo clippy --features="rev-sqlite" run: cargo clippy --features="rev-sqlite"
working-directory: frontend/rust-lib 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 - name: rustfmt shared-lib
run: cargo fmt --all -- --check run: cargo fmt --all -- --check
working-directory: shared-lib working-directory: shared-lib

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -44,7 +44,7 @@ env = { RUST_LOG = "info" }
description = "Run rust-lib unit tests" description = "Run rust-lib unit tests"
script = ''' script = '''
cd rust-lib 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] [tasks.shared_lib_unit_test]