feat: Import appflowy data (#4236)

* refactor: traits

* feat: import data

* chore: track database view

* fix: import

* refactor: collab doc state

* refactor: get collab doc state

* feat: batch create collab object

* fix: test

* ci: run docker compose if the server is not up

* chore: bump collab

* chore: update ci

* chore: update ci

* chore: update ci

* chore: implement ui

* chore: implement ui

* chore: implement ui
This commit is contained in:
Nathan.fooo
2023-12-29 13:02:27 +08:00
committed by GitHub
parent c821b8c4fe
commit 69469e9989
100 changed files with 2728 additions and 886 deletions

View File

@ -45,7 +45,7 @@ async fn supabase_create_database_test() {
}
let updates_by_oid = database_service
.batch_get_collab_updates(row_ids, CollabType::DatabaseRow, "fake_workspace_id")
.batch_get_collab_doc_state_db(row_ids, CollabType::DatabaseRow, "fake_workspace_id")
.await
.unwrap();

View File

@ -69,7 +69,12 @@ async fn supabase_get_folder_test() {
// let updates = collab_service.get_all_updates(&collab_object).await.unwrap();
let updates = folder_service
.get_folder_doc_state(&user.latest_workspace.id, user.user_id)
.get_collab_doc_state_f(
&user.latest_workspace.id,
user.user_id,
CollabType::Folder,
&user.latest_workspace.id,
)
.await
.unwrap();
assert_eq!(updates.len(), 2);
@ -80,20 +85,23 @@ async fn supabase_get_folder_test() {
.await
.unwrap();
}
let updates: Vec<Vec<u8>> = folder_service
.get_folder_doc_state(&user.latest_workspace.id, user.user_id)
let updates = folder_service
.get_collab_doc_state_f(
&user.latest_workspace.id,
user.user_id,
CollabType::Folder,
&user.latest_workspace.id,
)
.await
.unwrap();
assert_eq!(updates.len(), 1);
// Other the init sync, try to get the updates from the server.
let remote_update = updates.first().unwrap().clone();
let expected_update = doc
.transact_mut()
.encode_state_as_update_v1(&StateVector::default());
// check the update is the same as local document update.
assert_eq!(remote_update, expected_update);
assert_eq!(updates, expected_update);
}
/// This async test function checks the behavior of updates duplication in Supabase.
@ -148,13 +156,15 @@ async fn supabase_duplicate_updates_test() {
.send_init_sync(&collab_object, 3, vec![])
.await
.unwrap();
let first_init_sync_update: Vec<u8> = folder_service
.get_folder_doc_state(&user.latest_workspace.id, user.user_id)
let first_init_sync_update = folder_service
.get_collab_doc_state_f(
&user.latest_workspace.id,
user.user_id,
CollabType::Folder,
&user.latest_workspace.id,
)
.await
.unwrap()
.first()
.unwrap()
.clone();
.unwrap();
// simulate the duplicated updates.
let merged_update = merge_updates_v1(
@ -168,13 +178,16 @@ async fn supabase_duplicate_updates_test() {
.send_init_sync(&collab_object, 4, merged_update)
.await
.unwrap();
let second_init_sync_update: Vec<u8> = folder_service
.get_folder_doc_state(&user.latest_workspace.id, user.user_id)
let second_init_sync_update = folder_service
.get_collab_doc_state_f(
&user.latest_workspace.id,
user.user_id,
CollabType::Folder,
&user.latest_workspace.id,
)
.await
.unwrap()
.first()
.unwrap()
.clone();
.unwrap();
let doc_2 = Doc::new();
assert_eq!(first_init_sync_update.len(), second_init_sync_update.len());
let map = { doc_2.get_or_insert_map("map") };
@ -257,16 +270,19 @@ async fn supabase_diff_state_vector_test() {
// restore the doc with given updates.
let old_version_doc = Doc::new();
let map = { old_version_doc.get_or_insert_map("map") };
let updates: Vec<Vec<u8>> = folder_service
.get_folder_doc_state(&user.latest_workspace.id, user.user_id)
let doc_state = folder_service
.get_collab_doc_state_f(
&user.latest_workspace.id,
user.user_id,
CollabType::Folder,
&user.latest_workspace.id,
)
.await
.unwrap();
{
let mut txn = old_version_doc.transact_mut();
for update in updates {
let update = Update::decode_v1(&update).unwrap();
txn.apply_update(update);
}
let update = Update::decode_v1(&doc_state).unwrap();
txn.apply_update(update);
}
let txn = old_version_doc.transact();
let json = map.to_json(&txn);

View File

@ -21,7 +21,7 @@ async fn supabase_user_sign_up_test() {
let user: AuthResponse = user_service.sign_up(BoxAny::new(params)).await.unwrap();
assert!(!user.latest_workspace.id.is_empty());
assert!(!user.user_workspaces.is_empty());
assert!(!user.latest_workspace.database_storage_id.is_empty());
assert!(!user.latest_workspace.database_view_tracker_id.is_empty());
}
#[tokio::test]
@ -38,7 +38,7 @@ async fn supabase_user_sign_up_with_existing_uuid_test() {
.unwrap();
let user: AuthResponse = user_service.sign_up(BoxAny::new(params)).await.unwrap();
assert!(!user.latest_workspace.id.is_empty());
assert!(!user.latest_workspace.database_storage_id.is_empty());
assert!(!user.latest_workspace.database_view_tracker_id.is_empty());
assert!(!user.user_workspaces.is_empty());
}

View File

@ -120,8 +120,7 @@ pub async fn print_encryption_folder_snapshot(
.pop()
.unwrap();
let collab = Arc::new(
MutexCollab::new_with_raw_data(CollabOrigin::Empty, folder_id, vec![snapshot.blob], vec![])
.unwrap(),
MutexCollab::new_with_raw_data(CollabOrigin::Empty, folder_id, snapshot.blob, vec![]).unwrap(),
);
let folder_data = Folder::open(uid, collab, None)
.unwrap()