diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.lock b/frontend/appflowy_tauri/src-tauri/Cargo.lock index 68c2af6cce..ae9d6ff682 100644 --- a/frontend/appflowy_tauri/src-tauri/Cargo.lock +++ b/frontend/appflowy_tauri/src-tauri/Cargo.lock @@ -782,7 +782,7 @@ dependencies = [ [[package]] name = "collab" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "async-trait", @@ -802,7 +802,7 @@ dependencies = [ [[package]] name = "collab-database" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "async-trait", @@ -829,7 +829,7 @@ dependencies = [ [[package]] name = "collab-document" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "collab", @@ -847,7 +847,7 @@ dependencies = [ [[package]] name = "collab-entity" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "bytes", @@ -861,7 +861,7 @@ dependencies = [ [[package]] name = "collab-folder" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "chrono", @@ -897,7 +897,7 @@ dependencies = [ [[package]] name = "collab-plugins" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "async-trait", @@ -927,7 +927,7 @@ dependencies = [ [[package]] name = "collab-user" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "collab", diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.toml b/frontend/appflowy_tauri/src-tauri/Cargo.toml index 541313483c..216ee79960 100644 --- a/frontend/appflowy_tauri/src-tauri/Cargo.toml +++ b/frontend/appflowy_tauri/src-tauri/Cargo.toml @@ -67,13 +67,13 @@ client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "284 # To switch to the local path, run: # scripts/tool/update_collab_source.sh # ⚠️⚠️⚠️️ -collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } +collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock index 9c2d226003..7d90b2a331 100644 --- a/frontend/rust-lib/Cargo.lock +++ b/frontend/rust-lib/Cargo.lock @@ -724,7 +724,7 @@ dependencies = [ [[package]] name = "collab" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "async-trait", @@ -744,7 +744,7 @@ dependencies = [ [[package]] name = "collab-database" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "async-trait", @@ -771,7 +771,7 @@ dependencies = [ [[package]] name = "collab-document" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "collab", @@ -789,7 +789,7 @@ dependencies = [ [[package]] name = "collab-entity" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "bytes", @@ -803,7 +803,7 @@ dependencies = [ [[package]] name = "collab-folder" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "chrono", @@ -839,7 +839,7 @@ dependencies = [ [[package]] name = "collab-plugins" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "async-trait", @@ -869,7 +869,7 @@ dependencies = [ [[package]] name = "collab-user" version = "0.1.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=fe8f08fcc99ea56c78bfb746ccb0cd308126141d#fe8f08fcc99ea56c78bfb746ccb0cd308126141d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80#3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" dependencies = [ "anyhow", "collab", diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.toml index 700e5a91ee..ff9a8cf698 100644 --- a/frontend/rust-lib/Cargo.toml +++ b/frontend/rust-lib/Cargo.toml @@ -117,10 +117,10 @@ client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "284 # To switch to the local path, run: # scripts/tool/update_collab_source.sh # ⚠️⚠️⚠️️ -collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } -collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "fe8f08fcc99ea56c78bfb746ccb0cd308126141d" } +collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } +collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "3c2cb055e47ec9d6bff3d3aeb2a476b85d02cb80" } diff --git a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/import_af_data_folder_test.rs b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/import_af_data_folder_test.rs index 104bd3358d..b61c872658 100644 --- a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/import_af_data_folder_test.rs +++ b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/import_af_data_folder_test.rs @@ -111,9 +111,11 @@ async fn import_appflowy_data_folder_into_new_view_test() { // In the 040_local, only the first row has a document with content let row_document_id = database_row_document_id_from_row_id(&rows[0].id); + let row_document_view = test.get_view(&row_document_id).await; + assert_eq!(row_document_view.id, row_document_view.parent_view_id); + let row_document_data = test.get_document_data(&row_document_id).await; assert_json_include!(actual: json!(row_document_data), expected: expected_row_doc_json()); - drop(cleaner); } diff --git a/frontend/rust-lib/flowy-ai/tests/util/mod.rs b/frontend/rust-lib/flowy-ai/tests/util/mod.rs index 2d4377b4a7..42bdd7c921 100644 --- a/frontend/rust-lib/flowy-ai/tests/util/mod.rs +++ b/frontend/rust-lib/flowy-ai/tests/util/mod.rs @@ -2,6 +2,7 @@ use flowy_ai::config::OpenAISetting; // To run the OpenAI test, you need to create a .env file in the flowy-ai folder. // Use the format: OPENAI_API_KEY=your_api_key +#[allow(dead_code)] pub fn get_openai_config() -> Option { dotenv::from_filename(".env").ok()?; OpenAISetting::from_env().ok() diff --git a/frontend/rust-lib/flowy-document/src/manager.rs b/frontend/rust-lib/flowy-document/src/manager.rs index 3a8949364b..b711c738a5 100644 --- a/frontend/rust-lib/flowy-document/src/manager.rs +++ b/frontend/rust-lib/flowy-document/src/manager.rs @@ -110,32 +110,14 @@ impl DocumentManager { format!("document {} already exists", doc_id), )) } else { - let result: Result = self - .cloud_service - .get_document_doc_state(doc_id, &self.user_service.workspace_id()?) - .await; - - match result { - Ok(data) => { - let collab = self.collab_for_document(uid, doc_id, data, false).await?; - collab.lock().flush(); - }, - Err(err) => { - if err.is_record_not_found() { - let doc_state = - doc_state_from_document_data(doc_id, data.unwrap_or_else(default_document_data))? - .doc_state - .to_vec(); - let collab = self - .collab_for_document(uid, doc_id, doc_state, false) - .await?; - collab.lock().flush(); - } else { - return Err(err); - } - }, - } - + let doc_state = + doc_state_from_document_data(doc_id, data.unwrap_or_else(default_document_data))? + .doc_state + .to_vec(); + let collab = self + .collab_for_document(uid, doc_id, doc_state, false) + .await?; + collab.lock().flush(); Ok(()) } } 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.rs index 2105c41dd4..977cf0764f 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 @@ -1,7 +1,5 @@ -use crate::migrations::session_migration::migrate_session_with_user_uuid; - use crate::manager::run_collab_data_migration; - +use crate::migrations::session_migration::migrate_session_with_user_uuid; use crate::services::data_import::importer::load_collab_by_oid; use crate::services::db::UserDBPath; use crate::services::entities::{Session, UserPaths}; @@ -102,6 +100,7 @@ pub(crate) fn import_appflowy_data_folder( let mut database_view_ids_by_database_id: HashMap> = HashMap::new(); let row_object_ids = Mutex::new(HashSet::new()); + let row_document_object_ids = Mutex::new(HashSet::new()); let document_object_ids = Mutex::new(HashSet::new()); let database_object_ids = Mutex::new(HashSet::new()); let import_container_view_id = match &container_name { @@ -156,8 +155,17 @@ pub(crate) fn import_appflowy_data_folder( &mut all_imported_object_ids, &imported_collab_by_oid, &row_object_ids, + &row_document_object_ids, )?; + debug!( + "import row document ids: {:?}", + row_document_object_ids + .lock() + .iter() + .collect::>() + ); + // the object ids now only contains the document collab object ids for object_id in &all_imported_object_ids { if let Some(imported_collab) = imported_collab_by_oid.get(object_id) { @@ -174,7 +182,7 @@ pub(crate) fn import_appflowy_data_folder( } // create a root view that contains all the views - let child_views = import_workspace_views( + let (mut child_views, orphan_views) = import_workspace_views( &import_container_view_id, &mut old_to_new_id_map.lock(), &imported_session, @@ -182,7 +190,10 @@ pub(crate) fn import_appflowy_data_folder( )?; match container_name { - None => Ok(child_views), + None => { + child_views.extend(orphan_views); + Ok(child_views) + }, Some(container_name) => { let name = if container_name.is_empty() { format!( @@ -207,15 +218,18 @@ pub(crate) fn import_appflowy_data_folder( document_object_ids .lock() .insert(import_container_view_id.clone()); - let import_container_view = - ViewBuilder::new(session.user_id, session.user_workspace.id.clone()) - .with_view_id(import_container_view_id) - .with_layout(ViewLayout::Document) - .with_name(name) - .with_child_views(child_views) - .build(); + let mut import_container_views = + vec![ + ViewBuilder::new(session.user_id, session.user_workspace.id.clone()) + .with_view_id(import_container_view_id) + .with_layout(ViewLayout::Document) + .with_name(name) + .with_child_views(child_views) + .build(), + ]; - Ok(vec![import_container_view]) + import_container_views.extend(orphan_views); + Ok(import_container_views) }, } })?; @@ -280,6 +294,7 @@ fn migrate_databases<'a, W>( imported_object_ids: &mut Vec, imported_collab_by_oid: &HashMap, row_object_ids: &Mutex>, + row_document_object_ids: &Mutex>, ) -> Result<(), PersistenceError> where W: CollabKVAction<'a>, @@ -312,6 +327,8 @@ where 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.lock().renew_id(&old_row_id); + // The row document might not exist in the database row. But by querying the old_row_document_id, + // we can know the document of the row is exist or not. let new_row_document_id = database_row_document_id_from_row_id(&new_row_id); old_to_new_id_map @@ -328,7 +345,6 @@ where .iter() .map(|order| order.id.clone().into_inner()) .collect::>(); - row_object_ids.lock().extend(new_row_ids); }); @@ -369,18 +385,18 @@ where ); } + // 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 imported_collab_by_oid .get(&imported_row_document_id) .is_some() { let new_row_document_id = old_to_new_id_map.lock().renew_id(&imported_row_document_id); - info!( - "map row document from: {}, to: {}", - imported_row_document_id, new_row_document_id, - ); + row_document_object_ids.lock().insert(new_row_document_id); } } + Ok(()) } @@ -436,7 +452,7 @@ fn import_workspace_views<'a, W>( old_to_new_id_map: &mut OldToNewIdMap, other_session: &Session, other_collab_read_txn: &W, -) -> Result, PersistenceError> +) -> Result<(Vec, Vec), PersistenceError> where W: CollabKVAction<'a>, PersistenceError: From, @@ -523,7 +539,17 @@ where ) .collect::>(); - Ok(parent_views) + // the views in the all_views_map now, should be the orphan views + debug!("create orphan views: {:?}", all_views_map.keys()); + let mut orphan_views = vec![]; + for orphan_view in all_views_map.into_values() { + orphan_views.push(ParentChildViews { + parent_view: orphan_view, + child_views: vec![], + }); + } + + Ok((parent_views, orphan_views)) } fn parent_view_from_view(