Skip to content

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.

fix: import data (#6483)

Nathan.fooofd9b01ca27ef
diff --git a/.github/workflows/flutter_ci.yaml b/.github/workflows/flutter_ci.yaml
index d2eeb7078d..6b7e58b962 100644
--- a/.github/workflows/flutter_ci.yaml
+++ b/.github/workflows/flutter_ci.yaml
@@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: true
matrix:
- os: [ubuntu-latest]
+ os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
flutter_profile: development-linux-x86_64
@@ -73,7 +73,7 @@ jobs:
strategy:
fail-fast: true
matrix:
- os: [windows-2019]
+ os: [ windows-2019 ]
include:
- os: windows-2019
flutter_profile: development-windows-x86
@@ -100,7 +100,7 @@ jobs:
strategy:
fail-fast: true
matrix:
- os: [macos-latest]
+ os: [ macos-latest ]
include:
- os: macos-latest
flutter_profile: development-mac-x86_64
@@ -122,12 +122,12 @@ jobs:
flutter_profile: ${{ matrix.flutter_profile }}
unit_test:
- needs: [prepare-linux]
+ needs: [ prepare-linux ]
if: github.event.pull_request.draft != true
strategy:
fail-fast: false
matrix:
- os: [ubuntu-latest]
+ os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
flutter_profile: development-linux-x86_64
@@ -216,11 +216,11 @@ jobs:
shell: bash
cloud_integration_test:
- needs: [prepare-linux]
+ needs: [ prepare-linux ]
strategy:
fail-fast: false
matrix:
- os: [ubuntu-latest]
+ os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
flutter_profile: development-linux-x86_64
@@ -241,12 +241,15 @@ jobs:
cp deploy.env .env
sed -i 's|RUST_LOG=.*|RUST_LOG=trace|' .env
sed -i 's/GOTRUE_EXTERNAL_GOOGLE_ENABLED=.*/GOTRUE_EXTERNAL_GOOGLE_ENABLED=true/' .env
+ sed -i 's|GOTRUE_MAILER_AUTOCONFIRM=.*|GOTRUE_MAILER_AUTOCONFIRM=true|' .env
sed -i 's|API_EXTERNAL_URL=.*|API_EXTERNAL_URL=http://localhost|' .env
- name: Run Docker-Compose
working-directory: AppFlowy-Cloud
env:
- APPFLOWY_CLOUD_VERSION: 0.6.4-amd64
+ APPFLOWY_CLOUD_VERSION: 0.6.29-amd64
+ APPFLOWY_HISTORY_VERSION: 0.6.29-amd64
+ APPFLOWY_WORKER_VERSION: 0.6.29-amd64
run: |
container_id=$(docker ps --filter name=appflowy-cloud-appflowy_cloud-1 -q)
if [ -z "$container_id" ]; then
@@ -322,12 +325,12 @@ jobs:
# split the integration tests into different machines to minimize the time
integration_test_1:
- needs: [prepare-linux]
+ needs: [ prepare-linux ]
if: github.event.pull_request.draft != true
strategy:
fail-fast: false
matrix:
- os: [ubuntu-latest]
+ os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
target: "x86_64-unknown-linux-gnu"
@@ -352,12 +355,12 @@ jobs:
rust_target: ${{ matrix.target }}
integration_test_2:
- needs: [prepare-linux]
+ needs: [ prepare-linux ]
if: github.event.pull_request.draft != true
strategy:
fail-fast: false
matrix:
- os: [ubuntu-latest]
+ os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
target: "x86_64-unknown-linux-gnu"
@@ -382,12 +385,12 @@ jobs:
rust_target: ${{ matrix.target }}
integration_test_3:
- needs: [prepare-linux]
+ needs: [ prepare-linux ]
if: github.event.pull_request.draft != true
strategy:
fail-fast: false
matrix:
- os: [ubuntu-latest]
+ os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
target: "x86_64-unknown-linux-gnu"
diff --git a/.github/workflows/rust_ci.yaml b/.github/workflows/rust_ci.yaml
index 566aef3b7b..ab6c06461a 100644
--- a/.github/workflows/rust_ci.yaml
+++ b/.github/workflows/rust_ci.yaml
@@ -47,6 +47,8 @@ jobs:
working-directory: AppFlowy-Cloud
env:
APPFLOWY_CLOUD_VERSION: 0.6.4-amd64
+ APPFLOWY_HISTORY_VERSION: 0.6.29-amd64
+ APPFLOWY_WORKER_VERSION: 0.6.29-amd64
run: |
container_id=$(docker ps --filter name=appflowy-cloud-appflowy_cloud-1 -q)
if [ -z "$container_id" ]; then
@@ -127,12 +129,15 @@ jobs:
run: |
cp deploy.env .env
sed -i 's|RUST_LOG=.*|RUST_LOG=trace|' .env
+ sed -i 's|GOTRUE_MAILER_AUTOCONFIRM=.*|GOTRUE_MAILER_AUTOCONFIRM=true|' .env
sed -i 's|API_EXTERNAL_URL=.*|API_EXTERNAL_URL=http://localhost|' .env
- name: Ensure AppFlowy-Cloud is Running with Correct Version
working-directory: AppFlowy-Cloud
env:
APPFLOWY_CLOUD_VERSION: 0.6.4-amd64
+ APPFLOWY_HISTORY_VERSION: 0.6.29-amd64
+ APPFLOWY_WORKER_VERSION: 0.6.29-amd64
run: |
container_id=$(docker ps --filter name=appflowy-cloud-appflowy_cloud-1 -q)
if [ -z "$container_id" ]; then
diff --git a/frontend/appflowy_flutter/integration_test/desktop/cloud/cloud_runner.dart b/frontend/appflowy_flutter/integration_test/desktop/cloud/cloud_runner.dart
index de5ab91b7a..ca63315cf3 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/cloud/cloud_runner.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/cloud/cloud_runner.dart
@@ -3,8 +3,10 @@ import 'sidebar/sidebar_move_page_test.dart' as sidebar_move_page_test;
import 'uncategorized/uncategorized_test_runner.dart'
as uncategorized_test_runner;
import 'workspace/workspace_test_runner.dart' as workspace_test_runner;
+import 'data_migration/data_migration_test_runner.dart' as data_migration_test_runner;
Future<void> main() async {
+ data_migration_test_runner.main();
// uncategorized
uncategorized_test_runner.main();
@@ -16,4 +18,5 @@ Future<void> main() async {
// sidebar
sidebar_move_page_test.main();
+
}
diff --git a/frontend/appflowy_flutter/integration_test/desktop/cloud/uncategorized/anon_user_continue_test.dart b/frontend/appflowy_flutter/integration_test/desktop/cloud/data_migration/anon_user_data_migration_test.dart
similarity index 82%
rename from frontend/appflowy_flutter/integration_test/desktop/cloud/uncategorized/anon_user_continue_test.dart
rename to frontend/appflowy_flutter/integration_test/desktop/cloud/data_migration/anon_user_data_migration_test.dart
index 32666e0497..054e895b4a 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/cloud/uncategorized/anon_user_continue_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/cloud/data_migration/anon_user_data_migration_test.dart
@@ -33,7 +33,7 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('appflowy cloud', () {
- testWidgets('anon user and then sign in', (tester) async {
+ testWidgets('anon user -> sign in -> open imported space', (tester) async {
await tester.initializeAppFlowy(
cloudType: AuthenticatorType.appflowyCloudSelfHost,
);
@@ -42,6 +42,10 @@ void main() {
await tester.tapAnonymousSignInButton();
await tester.expectToSeeHomePageWithGetStartedPage();
+ const pageName = 'Test Document';
+ await tester.createNewPageWithNameUnderParent(name: pageName);
+ tester.expectToSeePageName(pageName);
+
// rename the name of the anon user
await tester.openSettings();
await tester.openSettingsPage(SettingsPage.account);
@@ -60,20 +64,16 @@ void main() {
// sign up with Google
await tester.tapGoogleLoginInButton();
+ // await tester.pumpAndSettle(const Duration(seconds: 16));
- // sign out
+ // open the imported space
await tester.expectToSeeHomePage();
- await tester.openSettings();
- await tester.openSettingsPage(SettingsPage.account);
+ await tester.clickSpaceHeader();
- // Scroll to sign-out
- await tester.scrollUntilVisible(
- find.byType(AccountSignInOutButton),
- 100,
- scrollable: find.findSettingsScrollable(),
- );
+ // After import the anon user data, we will create a new space for it
+ await tester.openSpace("Getting started");
+ await tester.openPage(pageName);
- await tester.logout();
await tester.pumpAndSettle();
});
});
diff --git a/frontend/appflowy_flutter/integration_test/desktop/cloud/data_migration/data_migration_test_runner.dart b/frontend/appflowy_flutter/integration_test/desktop/cloud/data_migration/data_migration_test_runner.dart
new file mode 100644
index 0000000000..a69c0480ce
--- /dev/null
+++ b/frontend/appflowy_flutter/integration_test/desktop/cloud/data_migration/data_migration_test_runner.dart
@@ -0,0 +1,5 @@
+import 'anon_user_data_migration_test.dart' as anon_user_test;
+
+void main() async {
+ anon_user_test.main();
+}
diff --git a/frontend/appflowy_flutter/integration_test/desktop/cloud/uncategorized/uncategorized_test_runner.dart b/frontend/appflowy_flutter/integration_test/desktop/cloud/uncategorized/uncategorized_test_runner.dart
index 51b20e1b35..094c766fa8 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/cloud/uncategorized/uncategorized_test_runner.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/cloud/uncategorized/uncategorized_test_runner.dart
@@ -1,4 +1,3 @@
-import 'anon_user_continue_test.dart' as anon_user_continue_test;
import 'appflowy_cloud_auth_test.dart' as appflowy_cloud_auth_test;
import 'empty_test.dart' as preset_af_cloud_env_test;
import 'user_setting_sync_test.dart' as user_sync_test;
@@ -7,5 +6,4 @@ void main() async {
preset_af_cloud_env_test.main();
appflowy_cloud_auth_test.main();
user_sync_test.main();
- anon_user_continue_test.main();
}
diff --git a/frontend/appflowy_flutter/integration_test/shared/auth_operation.dart b/frontend/appflowy_flutter/integration_test/shared/auth_operation.dart
index 1f2f23dc2c..88f9634afd 100644
--- a/frontend/appflowy_flutter/integration_test/shared/auth_operation.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/auth_operation.dart
@@ -10,9 +10,10 @@ import 'package:flutter_test/flutter_test.dart';
import 'util.dart';
extension AppFlowyAuthTest on WidgetTester {
- Future<void> tapGoogleLoginInButton() async {
+ Future<void> tapGoogleLoginInButton({bool pumpAndSettle = true}) async {
await tapButton(
find.byKey(signInWithGoogleButtonKey),
+ pumpAndSettle: pumpAndSettle,
);
}
diff --git a/frontend/appflowy_flutter/integration_test/shared/base.dart b/frontend/appflowy_flutter/integration_test/shared/base.dart
index 371cd9b839..bcd6cc10e5 100644
--- a/frontend/appflowy_flutter/integration_test/shared/base.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/base.dart
@@ -174,7 +174,7 @@ extension AppFlowyTestBase on WidgetTester {
await this.pumpAndSettle(
Duration(milliseconds: milliseconds),
EnginePhase.sendSemanticsUpdate,
- const Duration(seconds: 5),
+ const Duration(seconds: 15),
);
}
}
diff --git a/frontend/appflowy_flutter/integration_test/shared/common_operations.dart b/frontend/appflowy_flutter/integration_test/shared/common_operations.dart
index 1bd5d7aef1..dd0f221e26 100644
--- a/frontend/appflowy_flutter/integration_test/shared/common_operations.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/common_operations.dart
@@ -1,5 +1,6 @@
import 'dart:io';
+import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/sidebar_space_menu.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
@@ -411,6 +412,19 @@ extension CommonOperations on WidgetTester {
await tapButton(addPageButton);
}
+ /// Click the + button in the space header
+ Future<void> clickSpaceHeader() async {
+ await tapButton(find.byType(SidebarSpaceHeader));
+ }
+
+ Future<void> openSpace(String spaceName) async {
+ final space = find.descendant(
+ of: find.byType(SidebarSpaceMenuItem),
+ matching: find.text(spaceName),
+ );
+ await tapButton(space);
+ }
+
/// Create a new page on the top level
Future<void> createNewPage({
ViewLayoutPB layout = ViewLayoutPB.Document,
diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/setting_file_importer_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/setting_file_importer_bloc.dart
index 517b943b35..7a1d3efc45 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/settings/setting_file_importer_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/setting_file_importer_bloc.dart
@@ -1,4 +1,7 @@
+import 'package:appflowy/core/config/kv.dart';
+import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/plugins/database/application/defines.dart';
+import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
@@ -19,9 +22,17 @@ class SettingFileImportBloc
importAppFlowyDataFolder: (String path) async {
final formattedDate =
DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now());
+ final spaceId =
+ await getIt<KeyValueStorage>().get(KVKeys.lastOpenedSpaceId);
+
final payload = ImportAppFlowyDataPB.create()
..path = path
- ..importContainerName = "appflowy_import_$formattedDate";
+ ..importContainerName = "import_$formattedDate";
+
+ if (spaceId != null) {
+ payload.parentViewId = spaceId;
+ }
+
emit(
state.copyWith(loadingState: const LoadingState.loading()),
);
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_menu.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_menu.dart
index 057a636698..11ca090789 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_menu.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_menu.dart
@@ -31,7 +31,7 @@ class SidebarSpaceMenu extends StatelessWidget {
for (final space in state.spaces)
SizedBox(
height: HomeSpaceViewSizes.viewHeight,
- child: _SidebarSpaceMenuItem(
+ child: SidebarSpaceMenuItem(
space: space,
isSelected: state.currentSpace?.id == space.id,
),
@@ -53,8 +53,9 @@ class SidebarSpaceMenu extends StatelessWidget {
}
}
-class _SidebarSpaceMenuItem extends StatelessWidget {
- const _SidebarSpaceMenuItem({
+class SidebarSpaceMenuItem extends StatelessWidget {
+ const SidebarSpaceMenuItem({
+ super.key,
required this.space,
required this.isSelected,
});
diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock
index 744d039b5e..8e27e7709b 100644
--- a/frontend/appflowy_flutter/pubspec.lock
+++ b/frontend/appflowy_flutter/pubspec.lock
@@ -1535,10 +1535,10 @@ packages:
dependency: transitive
description:
name: platform
- sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
+ sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
url: "https://pub.dev"
source: hosted
- version: "3.1.5"
+ version: "3.1.4"
plugin_platform_interface:
dependency: "direct dev"
description:
@@ -1933,10 +1933,10 @@ packages:
dependency: transitive
description:
name: string_scanner
- sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
+ sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
- version: "1.3.0"
+ version: "1.2.0"
string_validator:
dependency: "direct main"
description:
@@ -2238,10 +2238,10 @@ packages:
dependency: transitive
description:
name: vm_service
- sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
+ sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
- version: "14.2.5"
+ version: "14.2.1"
watcher:
dependency: transitive
description:
diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.toml b/frontend/appflowy_tauri/src-tauri/Cargo.toml
index c1117f6c2a..5891c2d2c1 100644
--- a/frontend/appflowy_tauri/src-tauri/Cargo.toml
+++ b/frontend/appflowy_tauri/src-tauri/Cargo.toml
@@ -121,23 +121,23 @@ custom-protocol = ["tauri/custom-protocol"]
# scripts/tool/update_collab_source.sh
# ⚠️⚠️⚠️️
<<<<<<< Updated upstream
-collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
+collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
= = = = = = =
-collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
+collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
>>>>>>> Stashed changes
diff --git a/frontend/appflowy_web_app/src-tauri/Cargo.lock b/frontend/appflowy_web_app/src-tauri/Cargo.lock
index 20311e8fff..5f2c2a2ace 100644
--- a/frontend/appflowy_web_app/src-tauri/Cargo.lock
+++ b/frontend/appflowy_web_app/src-tauri/Cargo.lock
@@ -986,7 +986,7 @@ dependencies = [
[[package]]
name = "collab"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"arc-swap",
@@ -1011,7 +1011,7 @@ dependencies = [
[[package]]
name = "collab-database"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"async-trait",
@@ -1050,7 +1050,7 @@ dependencies = [
[[package]]
name = "collab-document"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"arc-swap",
@@ -1071,7 +1071,7 @@ dependencies = [
[[package]]
name = "collab-entity"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"bytes",
@@ -1091,7 +1091,7 @@ dependencies = [
[[package]]
name = "collab-folder"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"arc-swap",
@@ -1113,7 +1113,7 @@ dependencies = [
[[package]]
name = "collab-importer"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"async-recursion",
@@ -1168,7 +1168,7 @@ dependencies = [
[[package]]
name = "collab-plugins"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"async-stream",
@@ -1248,7 +1248,7 @@ dependencies = [
[[package]]
name = "collab-user"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"collab",
@@ -2738,6 +2738,7 @@ dependencies = [
"lib-infra",
"once_cell",
"protobuf",
+ "rayon",
"semver",
"serde",
"serde_json",
diff --git a/frontend/appflowy_web_app/src-tauri/Cargo.toml b/frontend/appflowy_web_app/src-tauri/Cargo.toml
index 11b1649a23..4eec8059f9 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 = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
+collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
# Working directory: frontend
diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock
index e40dccc189..5977c9e9f6 100644
--- a/frontend/rust-lib/Cargo.lock
+++ b/frontend/rust-lib/Cargo.lock
@@ -849,7 +849,7 @@ dependencies = [
[[package]]
name = "collab"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"arc-swap",
@@ -874,7 +874,7 @@ dependencies = [
[[package]]
name = "collab-database"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"async-trait",
@@ -913,7 +913,7 @@ dependencies = [
[[package]]
name = "collab-document"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"arc-swap",
@@ -934,7 +934,7 @@ dependencies = [
[[package]]
name = "collab-entity"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"bytes",
@@ -954,7 +954,7 @@ dependencies = [
[[package]]
name = "collab-folder"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"arc-swap",
@@ -976,7 +976,7 @@ dependencies = [
[[package]]
name = "collab-importer"
version = "0.1.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"async-recursion",
@@ -1031,7 +1031,7 @@ dependencies = [
[[package]]
name = "collab-plugins"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"async-stream",
@@ -1111,7 +1111,7 @@ dependencies = [
[[package]]
name = "collab-user"
version = "0.2.0"
-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d7dc26a906e3ce5d72a309e933f853f1e75da1cb#d7dc26a906e3ce5d72a309e933f853f1e75da1cb"
+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=d73579b0269b33856690c4b4d68bf22b4eb17a99#d73579b0269b33856690c4b4d68bf22b4eb17a99"
dependencies = [
"anyhow",
"collab",
@@ -2538,6 +2538,7 @@ dependencies = [
"quickcheck_macros",
"rand 0.8.5",
"rand_core 0.6.4",
+ "rayon",
"semver",
"serde",
"serde_json",
diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.toml
index 584dd92076..80a2227615 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 = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
-collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d7dc26a906e3ce5d72a309e933f853f1e75da1cb" }
+collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
+collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "d73579b0269b33856690c4b4d68bf22b4eb17a99" }
# Working directory: frontend
# To update the commit ID, run:
diff --git a/frontend/rust-lib/event-integration-test/src/lib.rs b/frontend/rust-lib/event-integration-test/src/lib.rs
index 760f217084..e846f7cf11 100644
--- a/frontend/rust-lib/event-integration-test/src/lib.rs
+++ b/frontend/rust-lib/event-integration-test/src/lib.rs
@@ -77,7 +77,7 @@ impl EventIntegrationTest {
let path = path_buf.to_str().unwrap().to_string();
let device_id = uuid::Uuid::new_v4().to_string();
let config = AppFlowyCoreConfig::new(
- Version::new(0, 5, 8),
+ Version::new(0, 7, 0),
path.clone(),
path,
device_id,
diff --git a/frontend/rust-lib/event-integration-test/src/user_event.rs b/frontend/rust-lib/event-integration-test/src/user_event.rs
index e11f645aec..68229f3567 100644
--- a/frontend/rust-lib/event-integration-test/src/user_event.rs
+++ b/frontend/rust-lib/event-integration-test/src/user_event.rs
@@ -175,6 +175,7 @@ impl EventIntegrationTest {
let payload = ImportAppFlowyDataPB {
path,
import_container_name: name,
+ parent_view_id: None,
};
match EventBuilder::new(self.clone())
.event(UserEvent::ImportAppFlowyDataFolder)
@@ -431,7 +432,7 @@ pub struct SignUpContext {
pub password: String,
}
-pub async fn user_localhost_af_cloud() {
+pub async fn use_localhost_af_cloud() {
AuthenticatorType::AppFlowyCloud.write_env();
let base_url =
std::env::var("af_cloud_test_base_url").unwrap_or("http://localhost:8000".to_string());
@@ -454,5 +455,5 @@ pub async fn user_localhost_af_cloud_with_nginx() {
std::env::set_var("af_cloud_test_base_url", "http://localhost");
std::env::set_var("af_cloud_test_ws_url", "ws://localhost/ws/v1");
std::env::set_var("af_cloud_test_gotrue_url", "http://localhost/gotrue");
- user_localhost_af_cloud().await
+ use_localhost_af_cloud().await
}
diff --git a/frontend/rust-lib/event-integration-test/tests/chat/ai_tool_test.rs b/frontend/rust-lib/event-integration-test/tests/chat/ai_tool_test.rs
index 51b6b05c0e..f8c2f08b50 100644
--- a/frontend/rust-lib/event-integration-test/tests/chat/ai_tool_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/chat/ai_tool_test.rs
@@ -1,4 +1,4 @@
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_ai::entities::CompletionTypePB;
@@ -6,7 +6,7 @@ use std::time::Duration;
#[tokio::test]
async fn af_cloud_complete_text_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
test.af_cloud_sign_up().await;
diff --git a/frontend/rust-lib/event-integration-test/tests/chat/chat_message_test.rs b/frontend/rust-lib/event-integration-test/tests/chat/chat_message_test.rs
index 9b3396b036..1a5f9356c4 100644
--- a/frontend/rust-lib/event-integration-test/tests/chat/chat_message_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/chat/chat_message_test.rs
@@ -1,5 +1,5 @@
use crate::util::receive_with_timeout;
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_ai::entities::ChatMessageListPB;
use flowy_ai::notification::ChatNotification;
@@ -10,7 +10,7 @@ use std::time::Duration;
#[tokio::test]
async fn af_cloud_create_chat_message_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
test.af_cloud_sign_up().await;
@@ -65,7 +65,7 @@ async fn af_cloud_create_chat_message_test() {
#[tokio::test]
async fn af_cloud_load_remote_system_message_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
test.af_cloud_sign_up().await;
diff --git a/frontend/rust-lib/event-integration-test/tests/document/af_cloud_test/edit_test.rs b/frontend/rust-lib/event-integration-test/tests/document/af_cloud_test/edit_test.rs
index ca5f1b8d13..42593c3e5b 100644
--- a/frontend/rust-lib/event-integration-test/tests/document/af_cloud_test/edit_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/document/af_cloud_test/edit_test.rs
@@ -1,18 +1,17 @@
+use crate::util::{receive_with_timeout, unzip};
use collab_document::blocks::DocumentData;
-use serde_json::json;
-use std::time::Duration;
-
+use collab_folder::SpaceInfo;
use event_integration_test::document_event::assert_document_data_equal;
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_core::DEFAULT_NAME;
use flowy_document::entities::{DocumentSyncState, DocumentSyncStatePB};
-
-use crate::util::{receive_with_timeout, unzip};
+use serde_json::json;
+use std::time::Duration;
#[tokio::test]
async fn af_cloud_edit_document_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
test.af_cloud_sign_up().await;
test.wait_ws_connected().await;
@@ -44,7 +43,7 @@ async fn af_cloud_edit_document_test() {
#[tokio::test]
async fn af_cloud_sync_anon_user_document_test() {
let (cleaner, user_db_path) = unzip("./tests/asset", "040_sync_local_document").unwrap();
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test =
EventIntegrationTest::new_with_user_data_path(user_db_path.clone(), DEFAULT_NAME.to_string())
.await;
@@ -56,6 +55,11 @@ async fn af_cloud_sync_anon_user_document_test() {
// view: SyncDocument
let views = test.get_all_workspace_views().await;
assert_eq!(views.len(), 3);
+ for view in views.iter() {
+ let space_info = serde_json::from_str::<SpaceInfo>(view.extra.as_ref().unwrap()).unwrap();
+ assert!(space_info.is_space);
+ }
+
let document_id = views[2].id.clone();
test.open_document(document_id.clone()).await;
diff --git a/frontend/rust-lib/event-integration-test/tests/document/af_cloud_test/file_upload_test.rs b/frontend/rust-lib/event-integration-test/tests/document/af_cloud_test/file_upload_test.rs
index 87e36deac6..36df9ac913 100644
--- a/frontend/rust-lib/event-integration-test/tests/document/af_cloud_test/file_upload_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/document/af_cloud_test/file_upload_test.rs
@@ -1,5 +1,5 @@
use crate::document::generate_random_bytes;
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_storage_pub::storage::FileUploadState;
use lib_infra::util::md5;
@@ -14,7 +14,7 @@ use tokio::time::timeout;
#[tokio::test]
async fn af_cloud_upload_big_file_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let mut test = EventIntegrationTest::new().await;
test.af_cloud_sign_up().await;
tokio::time::sleep(Duration::from_secs(6)).await;
@@ -78,7 +78,7 @@ async fn af_cloud_upload_big_file_test() {
#[tokio::test]
async fn af_cloud_upload_6_files_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
test.af_cloud_sign_up().await;
let workspace_id = test.get_current_workspace().await.id;
diff --git a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/anon_user_test.rs b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/anon_user_test.rs
index 99b20c85a9..0840bdec15 100644
--- a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/anon_user_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/anon_user_test.rs
@@ -1,4 +1,4 @@
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_core::DEFAULT_NAME;
use flowy_user::entities::AuthenticatorPB;
@@ -49,7 +49,7 @@ async fn migrate_anon_user_data_to_af_cloud_test() {
// view: Document2
// view: Grid1
// view: Grid2
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test =
EventIntegrationTest::new_with_user_data_path(user_db_path.clone(), DEFAULT_NAME.to_string())
.await;
@@ -103,7 +103,6 @@ async fn migrate_anon_user_data_to_af_cloud_test() {
);
// check second level
- assert_eq!(anon_second_level_views.len(), user_second_level_views.len());
assert_ne!(anon_second_level_views[0].id, user_second_level_views[0].id);
assert_eq!(
anon_second_level_views[0].name,
diff --git a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/auth_test.rs b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/auth_test.rs
index 3f9a5b3f01..7b31babd0e 100644
--- a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/auth_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/auth_test.rs
@@ -1,4 +1,4 @@
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_user::entities::UpdateUserProfilePayloadPB;
@@ -7,7 +7,7 @@ use crate::util::generate_test_email;
#[tokio::test]
async fn af_cloud_sign_up_test() {
// user_localhost_af_cloud_with_nginx().await;
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
let email = generate_test_email();
let user = test.af_cloud_sign_in_with_email(&email).await.unwrap();
@@ -16,7 +16,7 @@ async fn af_cloud_sign_up_test() {
#[tokio::test]
async fn af_cloud_update_user_metadata() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
let user = test.af_cloud_sign_up().await;
diff --git a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/import_af_data_folder_test.rs b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/import_af_data_folder_test.rs
index 1d952af3b4..eb48fb6c0e 100644
--- a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/import_af_data_folder_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/import_af_data_folder_test.rs
@@ -1,70 +1,40 @@
use crate::util::unzip;
use assert_json_diff::assert_json_include;
use collab_database::rows::database_row_document_id_from_row_id;
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_core::DEFAULT_NAME;
use flowy_user::errors::ErrorCode;
use serde_json::{json, Value};
use std::env::temp_dir;
-#[tokio::test]
-async fn import_appflowy_data_need_migration_test() {
- // In 037, the workspace array will be migrated to view.
- let import_container_name = "037_local".to_string();
- let (cleaner, user_db_path) = unzip("./tests/asset", &import_container_name).unwrap();
- // Getting started
- // Document1
- // Document2(fav)
- user_localhost_af_cloud().await;
- let test = EventIntegrationTest::new_with_name(DEFAULT_NAME).await;
- let _ = test.af_cloud_sign_up().await;
- test
- .import_appflowy_data(
- user_db_path.to_str().unwrap().to_string(),
- Some(import_container_name.clone()),
- )
- .await
- .unwrap();
- // after import, the structure is:
- // workspace:
- // view: Generate
- // view: Shared
- // view: 037_local
- // view: Getting Started
- // view: Document1
- // view: Document2
-
- let views = test.get_all_workspace_views().await;
- assert_eq!(views.len(), 3);
- assert_eq!(views[2].name, import_container_name);
-
- let child_views = test.get_view(&views[2].id).await.child_views;
- assert_eq!(child_views.len(), 1);
-
- let child_views = test.get_view(&child_views[0].id).await.child_views;
- assert_eq!(child_views.len(), 2);
- assert_eq!(child_views[0].name, "Document1");
- assert_eq!(child_views[1].name, "Document2");
- drop(cleaner);
-}
-
#[tokio::test]
async fn import_appflowy_data_folder_into_new_view_test() {
let import_container_name = "040_local".to_string();
let (cleaner, user_db_path) = unzip("./tests/asset", &import_container_name).unwrap();
// In the 040_local, the structure is:
- // workspace:
- // view: Document1
- // view: Document2
- // view: Grid1
- // view: Grid2
- user_localhost_af_cloud().await;
+ // Document1
+ // Document2
+ // Grid1
+ // Grid2
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new_with_name(DEFAULT_NAME).await;
let _ = test.af_cloud_sign_up().await;
+ let views = test.get_all_workspace_views().await;
+ assert_eq!(views[0].name, "General");
+ assert_eq!(views[1].name, "Shared");
+ assert_eq!(views.len(), 2);
+ let shared_space_id = views[1].id.clone();
+ let shared_space = test.get_view(&shared_space_id).await;
+
+ // by default, shared space is empty
+ assert!(shared_space.child_views.is_empty());
// after sign up, the initial workspace is created, so the structure is:
// workspace:
- // view: Getting Started
+ // General
+ // template_document
+ // template_document
+ // Shared
test
.import_appflowy_data(
@@ -75,24 +45,26 @@ async fn import_appflowy_data_folder_into_new_view_test() {
.unwrap();
// after import, the structure is:
// workspace:
- // view: Getting Started
- // view: 040_local
- // view: Document1
- // view: Document2
- // view: Grid1
- // view: Grid2
- let views = test.get_all_workspace_views().await;
- assert_eq!(views.len(), 3);
- assert_eq!(views[2].name, import_container_name);
+ // General
+ // template_document
+ // template_document
+ // 040_local
+ // Shared
+ let general_space = test.get_view(&shared_space_id).await;
+ let shared_sub_views = &general_space.child_views;
+ assert_eq!(shared_sub_views.len(), 1);
+ assert_eq!(shared_sub_views[0].name, import_container_name);
// the 040_local should be an empty document, so try to get the document data
- let _ = test.get_document_data(&views[2].id).await;
+ let _ = test.get_document_data(&shared_sub_views[0].id).await;
- let local_child_views = test.get_view(&views[2].id).await.child_views;
- assert_eq!(local_child_views.len(), 1);
- assert_eq!(local_child_views[0].name, "Document1");
+ let t_040_local_child_views = test.get_view(&shared_sub_views[0].id).await.child_views;
+ assert_eq!(t_040_local_child_views[0].name, "Document1");
- let document1_child_views = test.get_view(&local_child_views[0].id).await.child_views;
+ let document1_child_views = test
+ .get_view(&t_040_local_child_views[0].id)
+ .await
+ .child_views;
assert_eq!(document1_child_views.len(), 1);
assert_eq!(document1_child_views[0].name, "Document2");
@@ -122,12 +94,11 @@ async fn import_appflowy_data_folder_into_current_workspace_test() {
let import_container_name = "040_local".to_string();
let (cleaner, user_db_path) = unzip("./tests/asset", &import_container_name).unwrap();
// In the 040_local, the structure is:
- // workspace:
- // view: Document1
- // view: Document2
- // view: Grid1
- // view: Grid2
- user_localhost_af_cloud().await;
+ // Document1
+ // Document2
+ // Grid1
+ // Grid2
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new_with_name(DEFAULT_NAME).await;
let _ = test.af_cloud_sign_up().await;
// after sign up, the initial workspace is created, so the structure is:
@@ -138,20 +109,25 @@ async fn import_appflowy_data_folder_into_current_workspace_test() {
.import_appflowy_data(user_db_path.to_str().unwrap().to_string(), None)
.await
.unwrap();
- // after import, the structure is:
- // workspace:
- // view: General
- // view: Shared
- // view: Document1
- // view: Document2
- // view: Grid1
- // view: Grid2
let views = test.get_all_workspace_views().await;
- assert_eq!(views.len(), 3);
- assert_eq!(views[2].name, "Document1");
+ assert_eq!(views[0].name, "General");
+ assert_eq!(views[1].name, "Shared");
+ assert_eq!(views.len(), 2);
+ let shared_space_id = views[1].id.clone();
+ let shared_space_child_views = test.get_view(&shared_space_id).await.child_views;
+ assert_eq!(shared_space_child_views.len(), 1);
- let document_1_child_views = test.get_view(&views[2].id).await.child_views;
- assert_eq!(document_1_child_views.len(), 1);
+ // after import, the structure is:
+ // workspace:
+ // General
+ // Shared
+ // Document1
+ // Document2
+ // Grid1
+ // Grid2
+ let document_1 = test.get_view(&shared_space_child_views[0].id).await;
+ assert_eq!(document_1.name, "Document1");
+ let document_1_child_views = test.get_view(&document_1.id).await.child_views;
assert_eq!(document_1_child_views[0].name, "Document2");
let document2_child_views = test
@@ -165,33 +141,10 @@ async fn import_appflowy_data_folder_into_current_workspace_test() {
drop(cleaner);
}
-#[tokio::test]
-async fn import_appflowy_data_folder_into_new_view_test2() {
- let import_container_name = "040_local_2".to_string();
- let (cleaner, user_db_path) = unzip("./tests/asset", &import_container_name).unwrap();
- user_localhost_af_cloud().await;
- let test = EventIntegrationTest::new_with_name(DEFAULT_NAME).await;
- let _ = test.af_cloud_sign_up().await;
- test
- .import_appflowy_data(
- user_db_path.to_str().unwrap().to_string(),
- Some(import_container_name.clone()),
- )
- .await
- .unwrap();
-
- let views = test.get_all_workspace_views().await;
- assert_eq!(views.len(), 3);
- assert_eq!(views[2].name, import_container_name);
- assert_040_local_2_import_content(&test, &views[2].id).await;
-
- drop(cleaner);
-}
-
#[tokio::test]
async fn import_empty_appflowy_data_folder_test() {
let path = temp_dir();
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new_with_name(DEFAULT_NAME).await;
let _ = test.af_cloud_sign_up().await;
let error = test
@@ -217,9 +170,18 @@ async fn import_appflowy_data_folder_multiple_times_test() {
// Doc3_grid_1
// Doc3_grid_2
// Doc3_calendar_1
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new_with_name(DEFAULT_NAME).await;
let _ = test.af_cloud_sign_up().await;
+ let views = test.get_all_workspace_views().await;
+ assert_eq!(views[0].name, "General");
+ assert_eq!(views[1].name, "Shared");
+ assert_eq!(views.len(), 2);
+ let shared_space_id = views[1].id.clone();
+ let shared_space = test.get_view(&shared_space_id).await;
+ // by default, shared space is empty
+ assert!(shared_space.child_views.is_empty());
+
test
.import_appflowy_data(
user_db_path.to_str().unwrap().to_string(),
@@ -230,12 +192,22 @@ async fn import_appflowy_data_folder_multiple_times_test() {
// after import, the structure is:
// General
// Shared
- // 040_local_2
-
- let views = test.get_all_workspace_views().await;
- assert_eq!(views.len(), 3);
- assert_eq!(views[2].name, import_container_name);
- assert_040_local_2_import_content(&test, &views[2].id).await;
+ // 040_local_2
+ // Getting Started
+ // Doc1
+ // Doc2
+ // Grid1
+ // Doc3
+ // Doc3_grid_1
+ // Doc3_grid_2
+ // Doc3_calendar_1
+
+ let shared_space_children_views = test.get_view(&shared_space_id).await.child_views;
+ assert_eq!(shared_space_children_views.len(), 1);
+ let _040_local_view_id = shared_space_children_views[0].id.clone();
+ let _040_local_view = test.get_view(&_040_local_view_id).await;
+ assert_eq!(_040_local_view.name, import_container_name);
+ assert_040_local_2_import_content(&test, &_040_local_view_id).await;
test
.import_appflowy_data(
@@ -247,15 +219,13 @@ async fn import_appflowy_data_folder_multiple_times_test() {
// after import, the structure is:
// Generate
// Shared
- // 040_local_2
- // Getting started
- // 040_local_2
- // Getting started
- let views = test.get_all_workspace_views().await;
- assert_eq!(views.len(), 4);
- assert_eq!(views[3].name, import_container_name);
- assert_040_local_2_import_content(&test, &views[2].id).await;
- assert_040_local_2_import_content(&test, &views[3].id).await;
+ // 040_local_2
+ // 040_local_2
+ let shared_space_children_views = test.get_view(&shared_space_id).await.child_views;
+ assert_eq!(shared_space_children_views.len(), 2);
+ for view in shared_space_children_views {
+ assert_040_local_2_import_content(&test, &view.id).await;
+ }
drop(cleaner);
}
diff --git a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/member_test.rs b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/member_test.rs
index ca962ae726..e10f6b45d0 100644
--- a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/member_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/member_test.rs
@@ -1,5 +1,5 @@
use crate::user::af_cloud_test::util::get_synced_workspaces;
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
#[tokio::test]
@@ -35,7 +35,7 @@ async fn af_cloud_invite_workspace_member() {
#[tokio::test]
async fn af_cloud_add_workspace_member_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test_1 = EventIntegrationTest::new().await;
let user_1 = test_1.af_cloud_sign_up().await;
let workspace_id_1 = test_1.get_current_workspace().await.id;
@@ -57,7 +57,7 @@ async fn af_cloud_add_workspace_member_test() {
#[tokio::test]
async fn af_cloud_delete_workspace_member_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test_1 = EventIntegrationTest::new().await;
let user_1 = test_1.af_cloud_sign_up().await;
let workspace_id_1 = test_1.get_current_workspace().await.id;
@@ -78,7 +78,7 @@ async fn af_cloud_delete_workspace_member_test() {
#[tokio::test]
async fn af_cloud_leave_workspace_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test_1 = EventIntegrationTest::new().await;
test_1.af_cloud_sign_up().await;
let workspace_id_1 = test_1.get_current_workspace().await.id;
diff --git a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/workspace_test.rs b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/workspace_test.rs
index 99a0f99fb0..56cf22a4da 100644
--- a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/workspace_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/workspace_test.rs
@@ -2,7 +2,7 @@ use collab::core::collab::DataSource::DocStateV1;
use collab::core::origin::CollabOrigin;
use collab_entity::CollabType;
use collab_folder::Folder;
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use std::time::Duration;
use tokio::task::LocalSet;
@@ -12,7 +12,7 @@ use crate::user::af_cloud_test::util::get_synced_workspaces;
#[tokio::test]
async fn af_cloud_workspace_delete() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
let user_profile_pb = test.af_cloud_sign_up().await;
let workspaces = get_synced_workspaces(&test, user_profile_pb.id).await;
@@ -33,7 +33,7 @@ async fn af_cloud_workspace_delete() {
#[tokio::test]
async fn af_cloud_workspace_change_name_and_icon() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
let user_profile_pb = test.af_cloud_sign_up().await;
let workspaces = test.get_all_workspaces().await;
@@ -58,7 +58,7 @@ async fn af_cloud_workspace_change_name_and_icon() {
#[tokio::test]
async fn af_cloud_create_workspace_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
let user_profile_pb = test.af_cloud_sign_up().await;
@@ -98,7 +98,7 @@ async fn af_cloud_create_workspace_test() {
#[tokio::test]
async fn af_cloud_open_workspace_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test = EventIntegrationTest::new().await;
let _ = test.af_cloud_sign_up().await;
let default_document_name = "General";
@@ -160,7 +160,7 @@ async fn af_cloud_open_workspace_test() {
#[tokio::test]
async fn af_cloud_different_open_same_workspace_test() {
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
// Set up the primary client and sign them up to the cloud.
let test_runner = EventIntegrationTest::new().await;
diff --git a/frontend/rust-lib/event-integration-test/tests/user/local_test/import_af_data_local_test.rs b/frontend/rust-lib/event-integration-test/tests/user/local_test/import_af_data_local_test.rs
index c8c4d2def1..fe0c8b8341 100644
--- a/frontend/rust-lib/event-integration-test/tests/user/local_test/import_af_data_local_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/user/local_test/import_af_data_local_test.rs
@@ -1,5 +1,5 @@
use crate::util::unzip;
-use event_integration_test::user_event::user_localhost_af_cloud;
+use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_core::DEFAULT_NAME;
use std::time::Duration;
@@ -11,7 +11,7 @@ async fn import_appflowy_data_folder_into_new_view_test() {
let (imported_af_folder_cleaner, imported_af_data_path) =
unzip("./tests/asset", &import_container_name).unwrap();
- user_localhost_af_cloud().await;
+ use_localhost_af_cloud().await;
let test =
EventIntegrationTest::new_with_user_data_path(user_db_path.clone(), DEFAULT_NAME.to_string())
.await;
@@ -34,15 +34,22 @@ async fn import_appflowy_data_folder_into_new_view_test() {
// after import, the structure is:
// workspace:
- // view: Getting Started
- // view: 040_local
- // view: Document1
- // view: Document2
- // view: Grid1
- // view: Grid2
+ // Document1
+ // Document2
+ // Grid1
+ // Grid2
+ // 040_local
let views = test.get_all_workspace_views().await;
- assert_eq!(views.len(), 2);
- assert_eq!(views[1].name, import_container_name);
+ assert_eq!(views.len(), 1);
+ assert_eq!(views[0].name, "Document1");
+ assert_eq!(views[0].child_views.len(), 2);
+
+ for (index, view) in views[0].child_views.iter().enumerate() {
+ let view = test.get_view(&view.id).await;
+ if index == 1 {
+ assert_eq!(view.name, import_container_name);
+ }
+ }
drop(cleaner);
drop(imported_af_folder_cleaner);
diff --git a/frontend/rust-lib/event-integration-test/tests/user/migration_test/collab_db_restore.rs b/frontend/rust-lib/event-integration-test/tests/user/migration_test/collab_db_restore.rs
deleted file mode 100644
index 45f33c3cd9..0000000000
--- a/frontend/rust-lib/event-integration-test/tests/user/migration_test/collab_db_restore.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-use event_integration_test::EventIntegrationTest;
-use flowy_core::DEFAULT_NAME;
-
-use crate::util::unzip;
-
-#[tokio::test]
-async fn collab_db_restore_test() {
- let (cleaner, user_db_path) = unzip(
- "./tests/user/migration_test/history_user_db",
- "038_collab_db_corrupt_restore",
- )
- .unwrap();
- let test =
- EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string()).await;
-
- let views = test.get_all_workspace_views().await;
- assert_eq!(views.len(), 1);
-
- drop(cleaner);
-}
diff --git a/frontend/rust-lib/event-integration-test/tests/user/migration_test/mod.rs b/frontend/rust-lib/event-integration-test/tests/user/migration_test/mod.rs
index 42748e823a..940f03e64f 100644
--- a/frontend/rust-lib/event-integration-test/tests/user/migration_test/mod.rs
+++ b/frontend/rust-lib/event-integration-test/tests/user/migration_test/mod.rs
@@ -1,4 +1,2 @@
mod document_test;
mod version_test;
-
-mod collab_db_restore;
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.rs
index bc42042842..9f417e2ef8 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
@@ -138,7 +138,7 @@ impl FolderOperationHandler for DocumentFolderOperation {
let json_str = include_str!("../../assets/read_me.json");
let document_pb = JsonToDocumentParser::json_str_to_document(json_str).unwrap();
manager
- .create_document(uid, &view.parent_view.id, Some(document_pb.into()))
+ .create_document(uid, &view.view.id, Some(document_pb.into()))
.await
.unwrap();
view
@@ -355,6 +355,7 @@ impl FolderOperationHandler for DatabaseFolderOperation {
let database_row_encoded_collabs =
load_collab_by_object_ids(uid, &collab_read_txn, &row_oids)
+ .0
.into_iter()
.map(|(oid, collab)| {
collab
@@ -380,6 +381,7 @@ impl FolderOperationHandler for DatabaseFolderOperation {
let database_row_document_encoded_collabs =
load_collab_by_object_ids(uid, &collab_read_txn, &row_document_ids)
+ .0
.into_iter()
.map(|(oid, collab)| {
collab
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/user_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/user_deps.rs
index 816e04ed7f..85cbaa97f0 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/user_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/user_deps.rs
@@ -4,6 +4,7 @@ use collab_integrate::collab_builder::AppFlowyCollabBuilder;
use flowy_database2::DatabaseManager;
use flowy_error::FlowyResult;
use flowy_folder::manager::FolderManager;
+use flowy_folder_pub::entities::ImportFrom;
use flowy_sqlite::kv::KVStorePreferences;
use flowy_user::services::authenticate_user::AuthenticateUser;
use flowy_user::user_manager::UserManager;
@@ -45,12 +46,31 @@ pub struct UserWorkspaceServiceImpl {
#[async_trait]
impl UserWorkspaceService for UserWorkspaceServiceImpl {
- async fn did_import_views(&self, views: Vec<ParentChildViews>) -> FlowyResult<()> {
- self.folder_manager.insert_parent_child_views(views).await?;
+ async fn import_views(
+ &self,
+ source: &ImportFrom,
+ views: Vec<ParentChildViews>,
+ orphan_views: Vec<ParentChildViews>,
+ parent_view_id: Option<String>,
+ ) -> FlowyResult<()> {
+ match source {
+ ImportFrom::AnonUser => {
+ self
+ .folder_manager
+ .insert_views_as_spaces(views, orphan_views)
+ .await?;
+ },
+ ImportFrom::AppFlowyDataFolder => {
+ self
+ .folder_manager
+ .insert_views_with_parent(views, orphan_views, parent_view_id)
+ .await?;
+ },
+ }
Ok(())
}
- async fn did_import_database_views(
+ async fn import_database_views(
&self,
ids_by_database_id: HashMap<String, Vec<String>>,
) -> FlowyResult<()> {
diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs
index 6481cd7b8b..84d038964d 100644
--- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs
@@ -322,12 +322,10 @@ impl DatabaseViewEditor {
} else {
(None, None, vec![])
}
+ } else if let Ok(result) = controller.did_delete_row(row) {
+ (None, result.deleted_group, result.row_changesets)
} else {
- if let Ok(result) = controller.did_delete_row(&row) {
- (None, result.deleted_group, result.row_changesets)
- } else {
- (None, None, vec![])
- }
+ (None, None, vec![])
};
if let Some(inserted_group) = inserted_group {
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_filter.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_filter.rs
index 29112a4cc5..4632484651 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_filter.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_filter.rs
@@ -18,7 +18,7 @@ impl DateFilterPB {
let timestamp = if self.condition.is_filter_on_start_timestamp() {
cell_data.timestamp
} else {
- cell_data.end_timestamp.or_else(|| cell_data.timestamp)
+ cell_data.end_timestamp.or(cell_data.timestamp)
};
Some(strategy.filter(timestamp))
diff --git a/frontend/rust-lib/flowy-document/src/manager.rs b/frontend/rust-lib/flowy-document/src/manager.rs
index 32cdbaf549..45054ea51c 100644
--- a/frontend/rust-lib/flowy-document/src/manager.rs
+++ b/frontend/rust-lib/flowy-document/src/manager.rs
@@ -17,8 +17,8 @@ use collab_entity::CollabType;
use collab_plugins::CollabKVDB;
use dashmap::DashMap;
use lib_infra::util::timestamp;
-use tracing::trace;
use tracing::{event, instrument};
+use tracing::{info, trace};
use crate::document::{
subscribe_document_changed, subscribe_document_snapshot_state, subscribe_document_sync_state,
@@ -214,6 +214,10 @@ impl DocumentManager {
// If the document does not exist in local disk, try get the doc state from the cloud. This happens
// When user_device_a create a document and user_device_b open the document.
if !self.is_doc_exist(doc_id).await? {
+ info!(
+ "document {} not found in local disk, try to get the doc state from the cloud",
+ doc_id
+ );
doc_state = DataSource::DocStateV1(
self
.cloud_service
diff --git a/frontend/rust-lib/flowy-folder-pub/src/entities.rs b/frontend/rust-lib/flowy-folder-pub/src/entities.rs
index 5c002ec367..dc1676f09d 100644
--- a/frontend/rust-lib/flowy-folder-pub/src/entities.rs
+++ b/frontend/rust-lib/flowy-folder-pub/src/entities.rs
@@ -3,21 +3,28 @@ use collab_folder::{ViewIcon, ViewLayout};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
-pub enum ImportData {
- AppFlowyDataFolder { items: Vec<AppFlowyData> },
+pub struct ImportedAppFlowyData {
+ pub source: ImportFrom,
+ pub folder_data: ImportedFolderData,
+ pub collab_data: ImportedCollabData,
+ pub parent_view_id: Option<String>,
}
-pub enum AppFlowyData {
- Folder {
- views: Vec<ParentChildViews>,
- /// Used to update the [DatabaseViewTrackerList] when importing the database.
- database_view_ids_by_database_id: HashMap<String, Vec<String>>,
- },
- CollabObject {
- row_object_ids: Vec<String>,
- document_object_ids: Vec<String>,
- database_object_ids: Vec<String>,
- },
+pub enum ImportFrom {
+ AnonUser,
+ AppFlowyDataFolder,
+}
+
+pub struct ImportedFolderData {
+ pub views: Vec<ParentChildViews>,
+ pub orphan_views: Vec<ParentChildViews>,
+ /// Used to update the [DatabaseViewTrackerList] when importing the database.
+ pub database_view_ids_by_database_id: HashMap<String, Vec<String>>,
+}
+pub struct ImportedCollabData {
+ pub row_object_ids: Vec<String>,
+ pub document_object_ids: Vec<String>,
+ pub database_object_ids: Vec<String>,
}
pub struct ImportViews {
diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rs
index 4b87c1f81a..9bf9b15aaa 100644
--- a/frontend/rust-lib/flowy-folder/src/manager.rs
+++ b/frontend/rust-lib/flowy-folder/src/manager.rs
@@ -14,9 +14,7 @@ use crate::notification::{
};
use crate::publish_util::{generate_publish_name, view_pb_to_publish_view};
use crate::share::{ImportParams, ImportValue};
-use crate::util::{
- folder_not_init_error, insert_parent_child_views, workspace_data_not_sync_error,
-};
+use crate::util::{folder_not_init_error, workspace_data_not_sync_error};
use crate::view_operation::{
create_view, EncodedCollabWrapper, FolderOperationHandler, FolderOperationHandlers,
};
@@ -24,7 +22,7 @@ use arc_swap::ArcSwapOption;
use collab::core::collab::DataSource;
use collab::lock::RwLock;
use collab_entity::{CollabType, EncodedCollab};
-use collab_folder::hierarchy_builder::ParentChildViews;
+use collab_folder::hierarchy_builder::{ParentChildViews, SpacePermission, ViewExtraBuilder};
use collab_folder::{
Folder, FolderData, FolderNotify, Section, SectionItem, TrashInfo, View, ViewLayout, ViewUpdate,
Workspace,
@@ -346,20 +344,99 @@ impl FolderManager {
})
}
- pub async fn insert_parent_child_views(
+ /// All the views will become a space under the workspace.
+ pub async fn insert_views_as_spaces(
&self,
- views: Vec<ParentChildViews>,
+ mut views: Vec<ParentChildViews>,
+ orphan_views: Vec<ParentChildViews>,
) -> Result<(), FlowyError> {
- match self.mutex_folder.load_full() {
- None => Err(FlowyError::internal().with_context("The folder is not initialized")),
- Some(lock) => {
- let mut folder = lock.write().await;
- for view in views {
- insert_parent_child_views(&mut folder, view);
- }
- Ok(())
- },
+ let lock = self
+ .mutex_folder
+ .load_full()
+ .ok_or_else(|| FlowyError::internal().with_context("The folder is not initialized"))?;
+ let mut folder = lock.write().await;
+ let workspace_id = folder
+ .get_workspace_id()
+ .ok_or_else(|| FlowyError::internal().with_context("Cannot find the workspace ID"))?;
+
+ views.iter_mut().for_each(|view| {
+ view.view.parent_view_id = workspace_id.clone();
+ view.view.extra = Some(
+ serde_json::to_string(
+ &ViewExtraBuilder::new()
+ .is_space(true, SpacePermission::PublicToAll)
+ .build(),
+ )
+ .unwrap(),
+ );
+ });
+ let all_views = views.into_iter().chain(orphan_views.into_iter()).collect();
+ folder.insert_nested_views(all_views);
+
+ Ok(())
+ }
+
+ /// Inserts parent-child views into the folder. If a `parent_view_id` is provided,
+ /// it will be used to set the `parent_view_id` for all child views. If not, the latest
+ /// view (by `last_edited_time`) from the workspace will be used as the parent view.
+ ///
+ pub async fn insert_views_with_parent(
+ &self,
+ mut views: Vec<ParentChildViews>,
+ orphan_views: Vec<ParentChildViews>,
+ parent_view_id: Option<String>,
+ ) -> Result<(), FlowyError> {
+ let lock = self
+ .mutex_folder
+ .load_full()
+ .ok_or_else(|| FlowyError::internal().with_context("The folder is not initialized"))?;
+
+ // Obtain a write lock on the folder.
+ let mut folder = lock.write().await;
+
+ // Set the parent view ID for the child views.
+ if let Some(parent_view_id) = parent_view_id {
+ // If a valid parent_view_id is provided, set it for each child view.
+ if folder.get_view(&parent_view_id).is_some() {
+ info!(
+ "[AppFlowyData]: Attach parent-child views with the latest view: {:?}",
+ parent_view_id
+ );
+ views.iter_mut().for_each(|child_view| {
+ child_view.view.parent_view_id = parent_view_id.clone();
+ });
+ }
+ } else {
+ // If no parent_view_id is provided, find the latest view in the workspace.
+ let workspace_id = folder
+ .get_workspace_id()
+ .ok_or_else(|| FlowyError::internal().with_context("Cannot find the workspace ID"))?;
+
+ // Get the latest view based on the last_edited_time in the workspace.
+ match folder
+ .get_views_belong_to(&workspace_id)
+ .iter()
+ .max_by_key(|view| view.last_edited_time)
+ {
+ None => info!("[AppFlowyData]: No views found in the workspace"),
+ Some(latest_view) => {
+ info!(
+ "[AppFlowyData]: Attach parent-child views with the latest view: {}:{}, is_space: {:?}",
+ latest_view.id,
+ latest_view.name,
+ latest_view.space_info(),
+ );
+ views.iter_mut().for_each(|child_view| {
+ child_view.view.parent_view_id = latest_view.id.clone();
+ });
+ },
+ }
}
+
+ // Insert the views into the folder.
+ let all_views = views.into_iter().chain(orphan_views.into_iter()).collect();
+ folder.insert_nested_views(all_views);
+ Ok(())
}
pub async fn get_workspace_pb(&self) -> FlowyResult<WorkspacePB> {
diff --git a/frontend/rust-lib/flowy-folder/src/user_default.rs b/frontend/rust-lib/flowy-folder/src/user_default.rs
index 6e9e973f8e..6b8174de76 100644
--- a/frontend/rust-lib/flowy-folder/src/user_default.rs
+++ b/frontend/rust-lib/flowy-folder/src/user_default.rs
@@ -28,12 +28,12 @@ impl DefaultFolderBuilder {
let views = workspace_view_builder.write().await.build();
// Safe to unwrap because we have at least one view. check out the DocumentFolderOperation.
- let first_view = views.first().unwrap().parent_view.clone();
+ let first_view = views.first().unwrap().view.clone();
let first_level_views = views
.iter()
.map(|value| ViewIdentifier {
- id: value.parent_view.id.clone(),
+ id: value.view.id.clone(),
})
.collect::<Vec<_>>();
@@ -62,11 +62,11 @@ impl DefaultFolderBuilder {
impl From<&ParentChildViews> for ViewPB {
fn from(value: &ParentChildViews) -> Self {
view_pb_with_child_views(
- Arc::new(value.parent_view.clone()),
+ Arc::new(value.view.clone()),
value
- .child_views
+ .children
.iter()
- .map(|v| Arc::new(v.parent_view.clone()))
+ .map(|v| Arc::new(v.view.clone()))
.collect(),
)
}
diff --git a/frontend/rust-lib/flowy-folder/src/util.rs b/frontend/rust-lib/flowy-folder/src/util.rs
index 035e862713..89d49f8a23 100644
--- a/frontend/rust-lib/flowy-folder/src/util.rs
+++ b/frontend/rust-lib/flowy-folder/src/util.rs
@@ -1,8 +1,5 @@
use crate::entities::UserFolderPB;
-use collab_folder::hierarchy_builder::ParentChildViews;
-use collab_folder::Folder;
use flowy_error::{ErrorCode, FlowyError};
-use tracing::{event, instrument};
pub(crate) fn folder_not_init_error() -> FlowyError {
FlowyError::internal().with_context("Folder not initialized")
@@ -14,17 +11,3 @@ pub(crate) fn workspace_data_not_sync_error(uid: i64, workspace_id: &str) -> Flo
workspace_id: workspace_id.to_string(),
})
}
-
-#[instrument(level = "debug", skip(folder, view))]
-pub(crate) fn insert_parent_child_views(folder: &mut Folder, view: ParentChildViews) {
- event!(
- tracing::Level::DEBUG,
- "Inserting view: {}, view children: {}",
- view.parent_view.id,
- view.child_views.len()
- );
- folder.insert_view(view.parent_view, None);
- for child_view in view.child_views {
- insert_parent_child_views(folder, child_view);
- }
-}
diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/dto.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/dto.rs
index e2fc6944fc..0710bcc2b2 100644
--- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/dto.rs
+++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/dto.rs
@@ -60,7 +60,6 @@ pub fn user_profile_from_af_profile(
icon_url: icon_url.unwrap_or_default(),
openai_key: openai_key.unwrap_or_default(),
stability_ai_key: stability_ai_key.unwrap_or_default(),
- workspace_id: profile.latest_workspace_id.to_string(),
authenticator: Authenticator::AppFlowyCloud,
encryption_type,
uid: profile.uid,
diff --git a/frontend/rust-lib/flowy-user-pub/src/entities.rs b/frontend/rust-lib/flowy-user-pub/src/entities.rs
index 87b25acfd6..7c0c9e3e8a 100644
--- a/frontend/rust-lib/flowy-user-pub/src/entities.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/entities.rs
@@ -167,7 +167,6 @@ pub struct UserProfile {
pub icon_url: String,
pub openai_key: String,
pub stability_ai_key: String,
- pub workspace_id: String,
pub authenticator: Authenticator,
// If the encryption_sign is not empty, which means the user has enabled the encryption.
pub encryption_type: EncryptionType,
@@ -246,7 +245,6 @@ where
token: value.user_token().unwrap_or_default(),
icon_url,
openai_key,
- workspace_id: value.latest_workspace().id.to_owned(),
authenticator: auth_type.clone(),
encryption_type: value.encryption_type(),
stability_ai_key,
diff --git a/frontend/rust-lib/flowy-user-pub/src/workspace_service.rs b/frontend/rust-lib/flowy-user-pub/src/workspace_service.rs
index 79ab916acc..2b1b58ae05 100644
--- a/frontend/rust-lib/flowy-user-pub/src/workspace_service.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/workspace_service.rs
@@ -1,12 +1,19 @@
use collab_folder::hierarchy_builder::ParentChildViews;
use flowy_error::FlowyResult;
+use flowy_folder_pub::entities::ImportFrom;
use lib_infra::async_trait::async_trait;
use std::collections::HashMap;
#[async_trait]
pub trait UserWorkspaceService: Send + Sync {
- async fn did_import_views(&self, views: Vec<ParentChildViews>) -> FlowyResult<()>;
- async fn did_import_database_views(
+ async fn import_views(
+ &self,
+ source: &ImportFrom,
+ views: Vec<ParentChildViews>,
+ orphan_views: Vec<ParentChildViews>,
+ parent_view_id: Option<String>,
+ ) -> FlowyResult<()>;
+ async fn import_database_views(
&self,
ids_by_database_id: HashMap<String, Vec<String>>,
) -> FlowyResult<()>;
diff --git a/frontend/rust-lib/flowy-user/Cargo.toml b/frontend/rust-lib/flowy-user/Cargo.toml
index 3894ce0ee6..8eb7f06ee8 100644
--- a/frontend/rust-lib/flowy-user/Cargo.toml
+++ b/frontend/rust-lib/flowy-user/Cargo.toml
@@ -49,6 +49,7 @@ base64 = "^0.21"
tokio-stream = "0.1.14"
semver = "1.0.22"
validator = { workspace = true, features = ["derive"] }
+rayon = "1.10.0"
[dev-dependencies]
nanoid = "0.4.0"
diff --git a/frontend/rust-lib/flowy-user/src/entities/import_data.rs b/frontend/rust-lib/flowy-user/src/entities/import_data.rs
index 023e3f9cfd..a472b5d588 100644
--- a/frontend/rust-lib/flowy-user/src/entities/import_data.rs
+++ b/frontend/rust-lib/flowy-user/src/entities/import_data.rs
@@ -9,4 +9,7 @@ pub struct ImportAppFlowyDataPB {
#[pb(index = 2, one_of)]
pub import_container_name: Option<String>,
+
+ #[pb(index = 3, one_of)]
+ pub parent_view_id: Option<String>,
}
diff --git a/frontend/rust-lib/flowy-user/src/event_handler.rs b/frontend/rust-lib/flowy-user/src/event_handler.rs
index a941c94429..c954fd288f 100644
--- a/frontend/rust-lib/flowy-user/src/event_handler.rs
+++ b/frontend/rust-lib/flowy-user/src/event_handler.rs
@@ -277,7 +277,7 @@ 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)
+ 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);
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 e30aed3d33..e02c094637 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
@@ -8,6 +8,7 @@ use crate::user_manager::run_collab_data_migration;
use anyhow::anyhow;
use collab::core::collab::DataSource;
use collab::core::origin::CollabOrigin;
+
use collab::preclude::updates::decoder::Decode;
use collab::preclude::updates::encoder::Encode;
use collab::preclude::{Collab, Doc, ReadTxn, StateVector, Transact, Update};
@@ -18,28 +19,31 @@ use collab_database::rows::{database_row_document_id_from_row_id, mut_row_with_c
use collab_database::workspace_database::WorkspaceDatabaseBody;
use collab_document::document_data::default_document_collab_data;
use collab_entity::CollabType;
-use collab_folder::hierarchy_builder::{ParentChildViews, ViewBuilder};
+use collab_folder::hierarchy_builder::{NestedViews, ParentChildViews, ViewBuilder};
use collab_folder::{Folder, UserId, View, ViewIdentifier, ViewLayout};
use collab_integrate::{CollabKVAction, CollabKVDB, PersistenceError};
use collab_plugins::local_storage::kv::KVTransactionDB;
-use flowy_error::FlowyError;
+use flowy_error::{FlowyError, FlowyResult};
use flowy_folder_pub::cloud::gen_view_id;
-use flowy_folder_pub::entities::{AppFlowyData, ImportData};
+use flowy_folder_pub::entities::{
+ ImportFrom, ImportedAppFlowyData, ImportedCollabData, ImportedFolderData,
+};
use flowy_sqlite::kv::KVStorePreferences;
use flowy_user_pub::cloud::{UserCloudService, UserCollabParams};
use flowy_user_pub::entities::{user_awareness_object_id, Authenticator};
use flowy_user_pub::session::Session;
-use std::borrow::Borrow;
+use rayon::prelude::*;
use std::collections::{HashMap, HashSet};
+
use std::ops::{Deref, DerefMut};
use std::path::Path;
use std::sync::{Arc, Weak};
-use tracing::{debug, error, event, info, instrument, warn};
-
+use tracing::{error, event, info, instrument, warn};
pub(crate) struct ImportedFolder {
pub imported_session: Session,
pub imported_collab_db: Arc<CollabKVDB>,
pub container_name: Option<String>,
+ pub parent_view_id: Option<String>,
pub source: ImportedSource,
}
@@ -56,7 +60,14 @@ impl ImportedFolder {
}
}
-pub(crate) fn prepare_import(path: &str) -> anyhow::Result<ImportedFolder> {
+pub(crate) fn prepare_import(
+ path: &str,
+ parent_view_id: Option<String>,
+) -> anyhow::Result<ImportedFolder> {
+ info!(
+ "[AppflowyData]:importing data from path: {}, parent_view_id:{:?}",
+ path, parent_view_id
+ );
if !Path::new(path).exists() {
return Err(anyhow!("The path: {} is not exist", path));
}
@@ -71,12 +82,17 @@ pub(crate) fn prepare_import(path: &str) -> anyhow::Result<ImportedFolder> {
))?;
let collab_db_path = user_paths.collab_db_path(imported_session.user_id);
+ info!("[AppflowyData]: collab db path: {:?}", collab_db_path);
+
let sqlite_db_path = user_paths.sqlite_db_path(imported_session.user_id);
+ info!("[AppflowyData]: sqlite db path: {:?}", sqlite_db_path);
+
let imported_sqlite_db = flowy_sqlite::init(sqlite_db_path)
- .map_err(|err| anyhow!("open import collab db failed: {:?}", err))?;
+ .map_err(|err| anyhow!("[AppflowyData]: open import collab db failed: {:?}", err))?;
+
let imported_collab_db = Arc::new(
CollabKVDB::open(collab_db_path)
- .map_err(|err| anyhow!("open import collab db failed: {:?}", err))?,
+ .map_err(|err| anyhow!("[AppflowyData]: open import collab db failed: {:?}", err))?,
);
let imported_user = select_user_profile(
imported_session.user_id,
@@ -95,6 +111,7 @@ pub(crate) fn prepare_import(path: &str) -> anyhow::Result<ImportedFolder> {
imported_session,
imported_collab_db,
container_name: None,
+ parent_view_id,
source: ImportedSource::ExternalFolder,
})
}
@@ -117,12 +134,18 @@ fn migrate_user_awareness(
/// - log (log files with unique identifiers)
/// - 2761499 (other relevant files or directories, identified by unique numbers)
+#[instrument(level = "debug", skip_all, err)]
pub(crate) fn generate_import_data(
current_session: &Session,
workspace_id: &str,
- collab_db: &Arc<CollabKVDB>,
+ user_collab_db: &Arc<CollabKVDB>,
imported_folder: ImportedFolder,
-) -> anyhow::Result<ImportData> {
+) -> anyhow::Result<ImportedAppFlowyData> {
+ info!(
+ "[AppflowyData]:importing workspace: {}:{}",
+ imported_folder.imported_session.user_workspace.name,
+ imported_folder.imported_session.user_workspace.id,
+ );
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();
@@ -142,51 +165,39 @@ pub(crate) fn generate_import_data(
ImportedSource::AnonUser => workspace_id.to_string(),
};
- let views = collab_db.with_write_txn(|collab_write_txn| {
- let imported_collab_read_txn = imported_collab_db.read_txn();
+ let (views, orphan_views) = user_collab_db.with_write_txn(|current_collab_db_write_txn| {
+ let imported_collab_db_read_txn = imported_collab_db.read_txn();
// use the old_to_new_id_map to keep track of the other collab object id and the new collab object id
let mut old_to_new_id_map = OldToNewIdMap::new();
// 1. Get all the imported collab object ids
- let mut all_imported_object_ids = imported_collab_read_txn
+ let mut all_imported_object_ids = imported_collab_db_read_txn
.get_all_docs()
.map(|iter| iter.collect::<Vec<String>>())
.unwrap_or_default();
// when doing import, we don't want to import these objects:
// 1. user workspace
- // 2. database view tracker
- // 3. the user awareness
+ // 2. workspace database views
+ // 3. user awareness
// So we remove these object ids from the list
let user_workspace_id = &imported_session.user_workspace.id;
- let database_indexer_id = &imported_session.user_workspace.workspace_database_id;
+ let workspace_database_id = &imported_session.user_workspace.workspace_database_id;
let user_awareness_id =
user_awareness_object_id(&imported_session.user_uuid, user_workspace_id).to_string();
all_imported_object_ids.retain(|id| {
- id != user_workspace_id && id != database_indexer_id && id != &user_awareness_id
+ id != user_workspace_id && id != workspace_database_id && id != &user_awareness_id
});
- match imported_folder.source {
- ImportedSource::ExternalFolder => {
- // 2. mapping the database indexer ids
- mapping_workspace_database_ids(
- &mut old_to_new_id_map,
- &imported_session,
- &imported_collab_read_txn,
- &mut database_view_ids_by_database_id,
- &mut database_object_ids,
- )?;
- },
- ImportedSource::AnonUser => {
- // 2. migrate the database with views object
- migrate_database_with_views_object(
- &mut old_to_new_id_map,
- &imported_session,
- &imported_collab_read_txn,
- current_session,
- collab_write_txn,
- )?;
- },
+ // 2. mapping the workspace database ids
+ if let Err(err) = mapping_workspace_database_ids(
+ &mut old_to_new_id_map,
+ &imported_session,
+ &imported_collab_db_read_txn,
+ &mut database_view_ids_by_database_id,
+ &mut database_object_ids,
+ ) {
+ error!("[AppflowyData]:import workspace database fail: {}", err);
}
// remove the database view ids from the object ids. Because there are no physical collab object
@@ -199,100 +210,231 @@ pub(crate) fn generate_import_data(
all_imported_object_ids.retain(|id| !database_view_ids.contains(id));
// 3. load imported collab objects data.
- let mut imported_collab_by_oid = load_collab_by_object_ids(
+ let (mut imported_collab_by_oid, invalid_object_ids) = load_collab_by_object_ids(
imported_session.user_id,
- &imported_collab_read_txn,
+ &imported_collab_db_read_txn,
&all_imported_object_ids,
);
+ // remove the invalid object ids from the object ids
+ info!(
+ "[AppflowyData]: invalid object ids: {:?}",
+ invalid_object_ids
+ );
+ all_imported_object_ids.retain(|id| !invalid_object_ids.contains(id));
+ // the object ids now only contains the document collab object ids
+ all_imported_object_ids.iter().for_each(|object_id| {
+ old_to_new_id_map.exchange_new_id(object_id);
+ });
+
// import the database
- migrate_databases(
+ let MigrateDatabase {
+ database_view_ids ,
+ database_row_ids,
+ } = migrate_databases(
&mut old_to_new_id_map,
current_session,
- collab_write_txn,
+ current_collab_db_write_txn,
&mut all_imported_object_ids,
&mut imported_collab_by_oid,
&mut row_object_ids,
)?;
- // 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) {
- let new_object_id = old_to_new_id_map.exchange_new_id(object_id);
- document_object_ids.insert(new_object_id.clone());
- debug!("import from: {}, to: {}", object_id, new_object_id,);
- write_collab_object(
- imported_collab,
- current_session.user_id,
- &new_object_id,
- collab_write_txn,
- );
- }
- }
+ migrate_database_rows(
+ &mut old_to_new_id_map,
+ current_session,
+ current_collab_db_write_txn,
+ &mut imported_collab_by_oid,
+ database_row_ids,
+ )?;
// Update the parent view IDs of all top-level views to match the new container view ID, making
// them child views of the container. This ensures that the hierarchy within the imported
// structure is correctly maintained.
- let (mut child_views, orphan_views) = mapping_folder_views(
+ let MigrateViews {
+ child_views,
+ orphan_views,
+ mut invalid_orphan_views,
+ not_exist_parent_view_ids,
+ } = migrate_folder_views(
&import_container_view_id,
&mut old_to_new_id_map,
&imported_session,
- &imported_collab_read_txn,
+ &imported_collab_db_read_txn,
+ &imported_collab_by_oid,
+ &database_view_ids,
)?;
- match imported_folder.source {
+ // Create collaboration documents for views that don't have existing collaboration objects.
+ // 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);
+ }
+ }
+
+ let gen_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,
+ )
+ };
+ 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<_>>();
+
+ for gen_collab in gen_collabs {
+ document_object_ids.insert(gen_collab.object_id.clone());
+ write_gen_collab(gen_collab, current_collab_db_write_txn);
+ }
+
+ let (mut views, orphan_views) = match imported_folder.source {
ImportedSource::ExternalFolder => match imported_container_view_name {
- None => {
- child_views.extend(orphan_views);
- Ok(child_views)
- },
+ None => Ok::<(Vec<ParentChildViews>, Vec<ParentChildViews>), anyhow::Error>((
+ child_views,
+ orphan_views,
+ )),
Some(container_name) => {
// create a new view with given name and then attach views to it
- attach_to_new_view(
+ let child_views = vec![create_new_container_view(
current_session,
&mut document_object_ids,
&import_container_view_id,
- collab_write_txn,
+ current_collab_db_write_txn,
child_views,
- orphan_views,
container_name,
- )
+ )?];
+ Ok((child_views, orphan_views))
},
},
- ImportedSource::AnonUser => {
- child_views.extend(orphan_views);
- Ok(child_views)
- },
+ ImportedSource::AnonUser => Ok((child_views, orphan_views)),
+ }?;
+
+ if !invalid_orphan_views.is_empty() {
+ let other_view_id = gen_view_id().to_string();
+ invalid_orphan_views
+ .iter_mut()
+ .for_each(|parent_child_views| {
+ parent_child_views.view.parent_view_id = other_view_id.clone();
+ });
+ let mut other_view = create_new_container_view(
+ current_session,
+ &mut document_object_ids,
+ &other_view_id,
+ current_collab_db_write_txn,
+ invalid_orphan_views,
+ "Others".to_string(),
+ )?;
+
+ // if the views is empty, the other view is the top level view
+ // otherwise, the other view is the child view of the first view
+ if views.is_empty() {
+ views.push(other_view);
+ } else {
+ let first_view = views.first_mut().unwrap();
+ other_view.view.parent_view_id = first_view.view.id.clone();
+ first_view.children.push(other_view);
+ }
}
+
+ Ok((views, orphan_views))
})?;
- Ok(ImportData::AppFlowyDataFolder {
- items: vec![
- AppFlowyData::Folder {
- views,
- database_view_ids_by_database_id,
- },
- AppFlowyData::CollabObject {
- row_object_ids: row_object_ids.into_iter().collect(),
- database_object_ids: database_object_ids.into_iter().collect(),
- document_object_ids: document_object_ids.into_iter().collect(),
- },
- ],
+ let source = match imported_folder.source {
+ ImportedSource::ExternalFolder => ImportFrom::AppFlowyDataFolder,
+ ImportedSource::AnonUser => ImportFrom::AnonUser,
+ };
+
+ Ok(ImportedAppFlowyData {
+ source,
+ parent_view_id: imported_folder.parent_view_id,
+ folder_data: ImportedFolderData {
+ views,
+ orphan_views,
+ database_view_ids_by_database_id,
+ },
+ collab_data: ImportedCollabData {
+ row_object_ids: row_object_ids.into_iter().collect(),
+ database_object_ids: database_object_ids.into_iter().collect(),
+ document_object_ids: document_object_ids.into_iter().collect(),
+ },
})
}
-fn attach_to_new_view<'a, W>(
+
+fn create_empty_document_for_view<'a, W>(
+ uid: i64,
+ view_id: &str,
+ collab_write_txn: &'a W,
+) -> FlowyResult<()>
+where
+ W: CollabKVAction<'a>,
+ PersistenceError: From<W::Error>,
+{
+ let import_container_doc_state = default_document_collab_data(view_id)
+ .map_err(|err| PersistenceError::InvalidData(err.to_string()))?
+ .doc_state
+ .to_vec();
+
+ let collab = Collab::new_with_source(
+ CollabOrigin::Empty,
+ view_id,
+ DataSource::DocStateV1(import_container_doc_state),
+ vec![],
+ false,
+ )
+ .map_err(|err| PersistenceError::InvalidData(err.to_string()))?;
+
+ write_collab_object(
+ &collab,
+ uid,
+ view_id,
+ collab_write_txn,
+ CollabType::Document,
+ );
+ Ok(())
+}
+
+#[instrument(level = "debug", skip_all, err)]
+fn create_new_container_view<'a, W>(
current_session: &Session,
document_object_ids: &mut HashSet<String>,
import_container_view_id: &str,
collab_write_txn: &'a W,
- child_views: Vec<ParentChildViews>,
- orphan_views: Vec<ParentChildViews>,
+ mut child_views: Vec<ParentChildViews>,
container_name: String,
-) -> Result<Vec<ParentChildViews>, PersistenceError>
+) -> Result<ParentChildViews, PersistenceError>
where
W: CollabKVAction<'a>,
PersistenceError: From<W::Error>,
{
+ child_views.iter_mut().for_each(|parent_child_views| {
+ if parent_child_views.view.parent_view_id != import_container_view_id {
+ warn!(
+ "[AppflowyData]: The parent view id of the child views is not the import container view id: {}",
+ import_container_view_id
+ );
+ parent_child_views.view.parent_view_id = import_container_view_id.to_string();
+ }
+ });
+
let name = if container_name.is_empty() {
format!(
"import_{}",
@@ -307,32 +449,42 @@ where
.map_err(|err| PersistenceError::InvalidData(err.to_string()))?
.doc_state
.to_vec();
- import_collab_object_with_doc_state(
- import_container_doc_state,
+
+ let collab = Collab::new_with_source(
+ CollabOrigin::Empty,
+ import_container_view_id,
+ DataSource::DocStateV1(import_container_doc_state),
+ vec![],
+ false,
+ )?;
+ write_collab_object(
+ &collab,
current_session.user_id,
import_container_view_id,
collab_write_txn,
- )?;
+ CollabType::Document,
+ );
document_object_ids.insert(import_container_view_id.to_string());
- let mut import_container_views = vec![ViewBuilder::new(
+
+ let import_container_views = ViewBuilder::new(
current_session.user_id,
current_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()];
+ .with_children(child_views)
+ .build();
- import_container_views.extend(orphan_views);
Ok(import_container_views)
}
+#[instrument(level = "debug", skip_all, err)]
fn mapping_workspace_database_ids<'a, W>(
old_to_new_id_map: &mut OldToNewIdMap,
imported_session: &Session,
- imported_collab_read_txn: &W,
+ imported_collab_db_read_txn: &W,
database_view_ids_by_database_id: &mut HashMap<String, Vec<String>>,
database_object_ids: &mut HashSet<String>,
) -> Result<(), PersistenceError>
@@ -347,7 +499,7 @@ where
vec![],
false,
);
- imported_collab_read_txn.load_doc_with_txn(
+ imported_collab_db_read_txn.load_doc_with_txn(
imported_session.user_id,
&imported_session.user_workspace.workspace_database_id,
&mut workspace_database_collab.transact_mut(),
@@ -381,7 +533,7 @@ fn init_workspace_database_body(object_id: &str, collab: Collab) -> WorkspaceDat
Ok(body) => body,
Err(err) => {
error!(
- "🔴init workspace database body failed: {:?}, create a new one",
+ "[AppflowyData]:init workspace database body failed: {:?}, create a new one",
err
);
let collab = Collab::new_with_origin(CollabOrigin::Empty, object_id, vec![], false);
@@ -390,82 +542,34 @@ fn init_workspace_database_body(object_id: &str, collab: Collab) -> WorkspaceDat
}
}
-fn migrate_database_with_views_object<'a, 'b, W, R>(
- old_to_new_id_map: &mut OldToNewIdMap,
- old_user_session: &Session,
- 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 workspace_database_collab = Collab::new(
- old_user_session.user_id,
- &old_user_session.user_workspace.workspace_database_id,
- "migrate_device",
- vec![],
- false,
- );
- old_collab_r_txn.load_doc_with_txn(
- old_user_session.user_id,
- &old_user_session.user_workspace.workspace_database_id,
- &mut workspace_database_collab.transact_mut(),
- )?;
-
- let new_uid = new_user_session.user_id;
- let new_object_id = &new_user_session.user_workspace.workspace_database_id;
- let mut workspace_database_body = init_workspace_database_body(
- &old_user_session.user_workspace.workspace_database_id,
- workspace_database_collab,
- );
-
- for database_meta in workspace_database_body.get_all_database_meta() {
- workspace_database_body.update_database(&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;
- })
- }
-
- {
- let collab: &Collab = workspace_database_body.borrow();
- let txn = collab.transact();
- if let Err(err) = new_collab_w_txn.create_new_doc(new_uid, new_object_id, &txn) {
- error!("🔴migrate database storage failed: {:?}", err);
- }
- drop(txn);
- }
-
- Ok(())
+struct MigrateDatabase {
+ database_view_ids: HashSet<String>,
+ database_row_ids: HashMap<String, HashSet<String>>,
}
+#[instrument(level = "debug", skip_all, err)]
fn migrate_databases<'a, W>(
old_to_new_id_map: &mut OldToNewIdMap,
session: &Session,
collab_write_txn: &'a W,
- imported_object_ids: &mut Vec<String>,
+ all_imported_object_ids: &mut Vec<String>,
imported_collab_by_oid: &mut HashMap<String, Collab>,
row_object_ids: &mut HashSet<String>,
-) -> Result<(), PersistenceError>
+) -> Result<MigrateDatabase, PersistenceError>
where
W: CollabKVAction<'a>,
PersistenceError: From<W::Error>,
{
// Migrate databases
- let mut row_document_object_ids = HashSet::new();
let mut database_object_ids = vec![];
- let mut imported_database_row_object_ids: HashMap<String, HashSet<String>> = HashMap::new();
-
- for object_id in imported_object_ids.iter() {
+ let mut imported_database_row_ids: HashMap<String, HashSet<String>> = HashMap::new();
+ let mut imported_database_view_ids = HashSet::new();
+ let mut database_row_document_ids_pair = HashSet::new();
+ let all_imported_keys = imported_collab_by_oid
+ .keys()
+ .cloned()
+ .collect::<Vec<String>>();
+ for object_id in all_imported_object_ids.iter() {
if let Some(database_collab) = imported_collab_by_oid.get_mut(object_id) {
if !is_database_collab(database_collab) {
continue;
@@ -481,8 +585,12 @@ where
let old_database_id = database_view.database_id.clone();
let new_database_id = old_to_new_id_map.exchange_new_id(&database_view.database_id);
+ imported_database_view_ids.insert(new_view_id.clone());
database_view.id = new_view_id;
database_view.database_id = new_database_id;
+ database_view
+ .row_orders
+ .retain(|row_order| all_imported_keys.contains(&row_order.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);
@@ -490,12 +598,12 @@ where
// 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);
-
+ database_row_document_ids_pair
+ .insert((old_row_document_id.clone(), new_row_document_id.clone()));
old_to_new_id_map.insert(old_row_document_id.clone(), new_row_document_id);
-
row_order.id = RowId::from(new_row_id);
- imported_database_row_object_ids
+ imported_database_row_ids
.entry(old_database_id.clone())
.or_default()
.insert(old_row_id);
@@ -510,81 +618,137 @@ where
row_object_ids.extend(new_row_ids);
});
- let new_object_id = old_to_new_id_map.exchange_new_id(object_id);
- debug!(
- "migrate database from: {}, to: {}",
- object_id, new_object_id,
- );
+ let new_database_object_id = old_to_new_id_map.exchange_new_id(object_id);
write_collab_object(
database_collab,
session.user_id,
- &new_object_id,
+ &new_database_object_id,
collab_write_txn,
+ CollabType::Database,
);
}
}
+ // write database rows into disk
+ let gen_database_row_document_collabs = database_row_document_ids_pair
+ .par_iter()
+ .filter_map(|(old_object_id, new_object_id)| {
+ let imported_collab = imported_collab_by_oid.get(old_object_id)?;
+ gen_sv_and_doc_state(
+ session.user_id,
+ new_object_id,
+ imported_collab,
+ CollabType::Document,
+ )
+ })
+ .collect::<Vec<_>>();
+ for gen_collab in gen_database_row_document_collabs {
+ write_gen_collab(gen_collab, collab_write_txn);
+ }
+
// remove the database object ids from the object ids
- imported_object_ids.retain(|id| !database_object_ids.contains(id));
+ all_imported_object_ids.retain(|id| !database_object_ids.contains(id));
// remove database row object ids from the imported object ids
- imported_object_ids.retain(|id| {
- !imported_database_row_object_ids
+ all_imported_object_ids.retain(|id| {
+ !imported_database_row_ids
.values()
.flatten()
.any(|row_id| row_id == id)
});
+ let database_row_document_ids = database_row_document_ids_pair
+ .iter()
+ .map(|(old_object_id, _)| old_object_id.clone())
+ .collect::<HashSet<String>>();
+ all_imported_object_ids.retain(|id| !database_row_document_ids.contains(id));
+
+ Ok(MigrateDatabase {
+ database_view_ids: imported_database_view_ids,
+ database_row_ids: imported_database_row_ids,
+ })
+}
+
+#[instrument(level = "debug", skip_all, err)]
+fn migrate_database_rows<'a, W>(
+ old_to_new_id_map: &mut OldToNewIdMap,
+ session: &Session,
+ collab_write_txn: &'a W,
+ imported_collab_by_oid: &mut HashMap<String, Collab>,
+ imported_database_row_object_ids: HashMap<String, HashSet<String>>,
+) -> Result<(), PersistenceError>
+where
+ W: CollabKVAction<'a>,
+ PersistenceError: From<W::Error>,
+{
+ let mut row_document_ids = HashSet::new();
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) = imported_collab_by_oid.get_mut(&imported_row_id) {
+ imported_row_ids.iter().for_each(|imported_row_id| {
+ if let Some(imported_collab) = imported_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,
- );
-
+ let new_row_id = old_to_new_id_map.exchange_new_id(imported_row_id);
mut_row_with_collab(imported_collab, |row_update| {
row_update
.set_row_id(RowId::from(new_row_id.clone()))
.set_database_id(new_database_id.clone());
});
- write_collab_object(
- imported_collab,
- session.user_id,
- &new_row_id,
- collab_write_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);
+ 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.exchange_new_id(&imported_row_document_id);
- row_document_object_ids.insert(new_row_document_id);
+ row_document_ids.insert(new_row_document_id);
}
+ });
+
+ let gen_collabs = imported_row_ids
+ .par_iter()
+ .filter_map(|imported_row_id| {
+ let imported_collab = imported_collab_by_oid.get(imported_row_id)?;
+ match old_to_new_id_map.get_exchanged_id(imported_row_id) {
+ None => {
+ error!(
+ "[AppflowyData]: Can't find the new id for the imported row:{}",
+ imported_row_id
+ );
+ None
+ },
+ Some(new_row_id) => gen_sv_and_doc_state(
+ session.user_id,
+ new_row_id,
+ imported_collab,
+ CollabType::DatabaseRow,
+ ),
+ }
+ })
+ .collect::<Vec<_>>();
+
+ for gen_collab in gen_collabs {
+ write_gen_collab(gen_collab, collab_write_txn);
}
}
- debug!(
- "import row document ids: {:?}",
- row_document_object_ids.iter().collect::<Vec<&String>>()
- );
-
Ok(())
}
-fn write_collab_object<'a, W>(collab: &Collab, new_uid: i64, new_object_id: &str, w_txn: &'a W)
-where
+fn write_collab_object<'a, W>(
+ collab: &Collab,
+ new_uid: i64,
+ new_object_id: &str,
+ w_txn: &'a W,
+ collab_type: CollabType,
+) where
W: CollabKVAction<'a>,
PersistenceError: From<W::Error>,
{
- if let Ok(encode_collab) = collab.encode_collab_v1(|_| Ok::<(), PersistenceError>(())) {
+ if let Ok(encode_collab) =
+ collab.encode_collab_v1(|collab| collab_type.validate_require_data(collab))
+ {
if let Ok(update) = Update::decode_v1(&encode_collab.doc_state) {
let doc = Doc::new();
{
@@ -597,20 +761,19 @@ where
);
return;
}
+ drop(txn);
}
let txn = doc.transact();
let state_vector = txn.state_vector();
let doc_state = txn.encode_state_as_update_v1(&StateVector::default());
- info!(
- "import collab:{} with len: {}",
- new_object_id,
- doc_state.len()
- );
if let Err(err) =
w_txn.flush_doc(new_uid, &new_object_id, state_vector.encode_v1(), doc_state)
{
- error!("import collab:{} failed: {:?}", new_object_id, err);
+ error!(
+ "[AppflowyData]:import collab:{} failed: {:?}",
+ new_object_id, err
+ );
}
}
} else {
@@ -618,33 +781,76 @@ where
}
}
-fn import_collab_object_with_doc_state<'a, W>(
+struct GenCollab {
+ uid: i64,
+ sv: Vec<u8>,
doc_state: Vec<u8>,
- new_uid: i64,
- new_object_id: &str,
- w_txn: &'a W,
-) -> Result<(), anyhow::Error>
+ object_id: String,
+}
+
+fn write_gen_collab<'a, W>(collab: GenCollab, w_txn: &'a W)
where
W: CollabKVAction<'a>,
PersistenceError: From<W::Error>,
{
- let collab = Collab::new_with_source(
- CollabOrigin::Empty,
- new_object_id,
- DataSource::DocStateV1(doc_state),
- vec![],
- false,
- )?;
- write_collab_object(&collab, new_uid, new_object_id, w_txn);
- Ok(())
+ if let Err(err) = w_txn.flush_doc(collab.uid, &collab.object_id, collab.sv, collab.doc_state) {
+ error!(
+ "[AppflowyData]:import collab:{} failed: {:?}",
+ collab.object_id, err
+ );
+ }
}
-fn mapping_folder_views<'a, W>(
+fn gen_sv_and_doc_state(
+ uid: i64,
+ object_id: &str,
+ collab: &Collab,
+ collab_type: CollabType,
+) -> Option<GenCollab> {
+ let encoded_collab = collab
+ .encode_collab_v1(|collab| collab_type.validate_require_data(collab))
+ .ok()?;
+ let update = Update::decode_v1(&encoded_collab.doc_state).ok()?;
+ let doc = Doc::new();
+ let mut txn = doc.transact_mut();
+ if let Err(e) = txn.apply_update(update) {
+ error!(
+ "Collab {} failed to apply update: {}",
+ collab.object_id(),
+ e
+ );
+ return None;
+ }
+ drop(txn);
+
+ let txn = doc.transact();
+ let state_vector = txn.state_vector();
+ let doc_state = txn.encode_state_as_update_v1(&StateVector::default());
+ Some(GenCollab {
+ uid,
+ sv: state_vector.encode_v1(),
+ doc_state,
+ object_id: object_id.to_string(),
+ })
+}
+
+struct MigrateViews {
+ child_views: Vec<ParentChildViews>,
+ orphan_views: Vec<ParentChildViews>,
+ invalid_orphan_views: Vec<ParentChildViews>,
+ #[allow(dead_code)]
+ not_exist_parent_view_ids: Vec<String>,
+}
+
+#[instrument(level = "debug", skip_all, err)]
+fn migrate_folder_views<'a, W>(
root_view_id: &str,
old_to_new_id_map: &mut OldToNewIdMap,
imported_session: &Session,
- imported_collab_read_txn: &W,
-) -> Result<(Vec<ParentChildViews>, Vec<ParentChildViews>), PersistenceError>
+ imported_collab_db_read_txn: &W,
+ imported_collab_by_oid: &HashMap<String, Collab>,
+ database_view_ids: &HashSet<String>,
+) -> Result<MigrateViews, PersistenceError>
where
W: CollabKVAction<'a>,
PersistenceError: From<W::Error>,
@@ -656,21 +862,69 @@ where
vec![],
false,
);
- imported_collab_read_txn.load_doc_with_txn(
- imported_session.user_id,
- &imported_session.user_workspace.id,
- &mut imported_folder_collab.transact_mut(),
- )?;
+
+ imported_collab_db_read_txn
+ .load_doc_with_txn(
+ imported_session.user_id,
+ &imported_session.user_workspace.id,
+ &mut imported_folder_collab.transact_mut(),
+ )
+ .map_err(|err| {
+ PersistenceError::Internal(anyhow!(
+ "[AppflowyData]: Can't load the user:{} folder:{}. {}",
+ imported_session.user_id,
+ imported_session.user_workspace.id,
+ err
+ ))
+ })?;
let other_user_id = UserId::from(imported_session.user_id);
- let imported_folder = Folder::open(other_user_id, imported_folder_collab, None)
- .map_err(|err| PersistenceError::InvalidData(err.to_string()))?;
+ let imported_folder =
+ Folder::open(other_user_id, imported_folder_collab, None).map_err(|err| {
+ PersistenceError::Internal(anyhow!("[AppflowyData]:Can't open folder:{}", err))
+ })?;
- let imported_folder_data = imported_folder
+ let mut imported_folder_data = imported_folder
.get_folder_data(&imported_session.user_workspace.id)
.ok_or(PersistenceError::Internal(anyhow!(
- "Can't read the folder data"
+ "[AppflowyData]: Can't read the folder data"
)))?;
+ // Only import views whose collab data is available
+ imported_folder_data.views.iter_mut().for_each(|view| {
+ view.children.retain(|view_identifier| {
+ let new_view_id = old_to_new_id_map.exchange_new_id(&view_identifier.id);
+ if database_view_ids.contains(&new_view_id) {
+ true
+ } else {
+ imported_collab_by_oid.contains_key(&view_identifier.id)
+ }
+ });
+ });
+ let mut not_exist_parent_view_ids = vec![];
+ imported_folder_data.views.retain(|view| {
+ let new_view_id = old_to_new_id_map.exchange_new_id(&view.id);
+ // If the view is a database view, it should be in the database view ids
+ if view.layout.is_database() && !database_view_ids.contains(&new_view_id) {
+ error!(
+ "[AppflowyData]: The database view:{} is not in the database view ids",
+ view.id
+ );
+ }
+
+ if database_view_ids.contains(&new_view_id) {
+ true
+ } else {
+ if view.space_info().is_some() {
+ if !imported_collab_by_oid.contains_key(&view.id) {
+ not_exist_parent_view_ids.push(new_view_id);
+ }
+ true
+ } else {
+ imported_collab_by_oid.contains_key(&view.id)
+ }
+ }
+ });
+
// replace the old parent view id of the workspace
old_to_new_id_map.0.insert(
imported_session.user_workspace.id.clone(),
@@ -685,7 +939,7 @@ where
.collect::<Vec<String>>();
// 1. Replace the views id with new view id
- let mut first_level_views = imported_folder_data
+ let mut views_not_in_trash = imported_folder_data
.workspace
.child_views
.items
@@ -693,7 +947,7 @@ where
.filter(|view| !trash_ids.contains(&view.id))
.collect::<Vec<ViewIdentifier>>();
- first_level_views.iter_mut().for_each(|view_identifier| {
+ views_not_in_trash.iter_mut().for_each(|view_identifier| {
view_identifier.id = old_to_new_id_map.exchange_new_id(&view_identifier.id);
});
@@ -718,27 +972,74 @@ where
.collect::<HashMap<String, View>>();
// 5. create the parent views. Each parent view contains the children views.
- let parent_views = first_level_views
+ let parent_views = views_not_in_trash
.into_iter()
.flat_map(
|view_identifier| match all_views_map.remove(&view_identifier.id) {
- None => None,
+ None => {
+ warn!(
+ "[AppflowyData]: Can't find the view:{} in the all views map",
+ view_identifier.id
+ );
+ None
+ },
Some(view) => parent_view_from_view(view, &mut all_views_map),
},
)
.collect::<Vec<ParentChildViews>>();
// 6. after the parent views are created, the all_views_map only contains the orphan views
- debug!("create orphan views: {:?}", all_views_map.keys());
+ info!(
+ "[AppflowyData]: create orphan views: {:?}",
+ all_views_map.keys()
+ );
+ let parent_views = NestedViews {
+ views: parent_views,
+ };
+
let mut orphan_views = vec![];
+ let mut invalid_orphan_views = vec![];
for orphan_view in all_views_map.into_values() {
- orphan_views.push(ParentChildViews {
- parent_view: orphan_view,
- child_views: vec![],
- });
+ // when the view's parent view id is the same as its view id, it will be considered as the orphan view
+ // currently, only the document in database row follows this rule
+ if orphan_view.id == orphan_view.parent_view_id {
+ orphan_views.push(ParentChildViews {
+ view: orphan_view,
+ children: vec![],
+ });
+ continue;
+ }
+
+ if parent_views
+ .find_view(&orphan_view.parent_view_id)
+ .is_none()
+ {
+ invalid_orphan_views.push(ParentChildViews {
+ view: orphan_view,
+ children: vec![],
+ });
+ } else {
+ orphan_views.push(ParentChildViews {
+ view: orphan_view,
+ children: vec![],
+ });
+ }
}
- Ok((parent_views, orphan_views))
+ info!(
+ "[AppflowyData]: parent views: {}, orphan views: {}, invalid orphan views: {}, views without collab data: {}",
+ parent_views.len(),
+ orphan_views.len(),
+ invalid_orphan_views.len(),
+ not_exist_parent_view_ids.len()
+ );
+
+ Ok(MigrateViews {
+ child_views: parent_views.views,
+ orphan_views,
+ invalid_orphan_views,
+ not_exist_parent_view_ids,
+ })
}
fn parent_view_from_view(
@@ -757,8 +1058,8 @@ fn parent_view_from_view(
.collect::<Vec<ParentChildViews>>();
Some(ParentChildViews {
- parent_view,
- child_views,
+ view: parent_view,
+ children: child_views,
})
}
@@ -776,6 +1077,10 @@ impl OldToNewIdMap {
.or_insert(gen_view_id().to_string());
(*view_id).clone()
}
+
+ fn get_exchanged_id(&self, old_id: &str) -> Option<&String> {
+ self.0.get(old_id)
+ }
}
impl Deref for OldToNewIdMap {
@@ -798,7 +1103,7 @@ pub async fn upload_collab_objects_data(
user_collab_db: Weak<CollabKVDB>,
workspace_id: &str,
user_authenticator: &Authenticator,
- appflowy_data: AppFlowyData,
+ collab_data: ImportedCollabData,
user_cloud_service: Arc<dyn UserCloudService>,
) -> Result<(), FlowyError> {
// Only support uploading the collab data when the current server is AppFlowy Cloud server
@@ -806,72 +1111,81 @@ pub async fn upload_collab_objects_data(
return Ok(());
}
- match appflowy_data {
- AppFlowyData::Folder { .. } => {},
- AppFlowyData::CollabObject {
- row_object_ids,
- document_object_ids,
- database_object_ids,
- } => {
- 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("The collab db has been dropped, indicating that the user has switched to a new account")
- })?;
-
- let collab_read = user_collab_db.read_txn();
- let mut object_by_collab_type = HashMap::new();
-
- event!(tracing::Level::DEBUG, "upload database collab data");
- object_by_collab_type.insert(
- CollabType::Database,
- load_and_process_collab_data(uid, &collab_read, &database_object_ids),
- );
+ let ImportedCollabData {
+ row_object_ids,
+ document_object_ids,
+ database_object_ids,
+ } = collab_data;
+ {
+ 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(
+ "The collab db has been dropped, indicating that the user has switched to a new account",
+ )
+ })?;
- event!(tracing::Level::DEBUG, "upload document collab data");
- object_by_collab_type.insert(
- CollabType::Document,
- load_and_process_collab_data(uid, &collab_read, &document_object_ids),
- );
+ let collab_read = user_collab_db.read_txn();
+ let mut object_by_collab_type = HashMap::new();
- event!(tracing::Level::DEBUG, "upload database row collab data");
- object_by_collab_type.insert(
- CollabType::DatabaseRow,
- load_and_process_collab_data(uid, &collab_read, &row_object_ids),
- );
- Ok::<_, FlowyError>(object_by_collab_type)
- })
- .await??;
-
- let mut size_counter = 0;
- let mut objects: Vec<UserCollabParams> = vec![];
- for (collab_type, encoded_collab_by_oid) in object_by_collab_type {
- for (oid, encoded_collab) in encoded_collab_by_oid {
- let obj_size = encoded_collab.len();
- // Add the current object to the batch.
- objects.push(UserCollabParams {
- object_id: oid,
- encoded_collab,
- collab_type: collab_type.clone(),
- });
- size_counter += obj_size;
- }
- }
+ event!(
+ tracing::Level::DEBUG,
+ "[AppflowyData]:upload database collab data"
+ );
+ object_by_collab_type.insert(
+ CollabType::Database,
+ load_and_process_collab_data(uid, &collab_read, &database_object_ids),
+ );
- // Spawn a new task to upload the collab objects data in the background. If the
- // upload fails, we will retry the upload later.
- // af_spawn(async move {
- if !objects.is_empty() {
- batch_create(
- uid,
- workspace_id,
- &user_cloud_service,
- &size_counter,
- objects,
- )
- .await;
+ event!(
+ tracing::Level::DEBUG,
+ "[AppflowyData]:upload document collab data"
+ );
+ object_by_collab_type.insert(
+ CollabType::Document,
+ load_and_process_collab_data(uid, &collab_read, &document_object_ids),
+ );
+
+ event!(
+ tracing::Level::DEBUG,
+ "[AppflowyData]:upload database row collab data"
+ );
+ object_by_collab_type.insert(
+ CollabType::DatabaseRow,
+ load_and_process_collab_data(uid, &collab_read, &row_object_ids),
+ );
+ Ok::<_, FlowyError>(object_by_collab_type)
+ })
+ .await??;
+
+ let mut size_counter = 0;
+ let mut objects: Vec<UserCollabParams> = vec![];
+ for (collab_type, encoded_collab_by_oid) in object_by_collab_type {
+ for (oid, encoded_collab) in encoded_collab_by_oid {
+ let obj_size = encoded_collab.len();
+ // Add the current object to the batch.
+ objects.push(UserCollabParams {
+ object_id: oid,
+ encoded_collab,
+ collab_type: collab_type.clone(),
+ });
+ size_counter += obj_size;
}
- // });
- },
+ }
+
+ // Spawn a new task to upload the collab objects data in the background. If the
+ // upload fails, we will retry the upload later.
+ // af_spawn(async move {
+ if !objects.is_empty() {
+ batch_create(
+ uid,
+ workspace_id,
+ &user_cloud_service,
+ &size_counter,
+ objects,
+ )
+ .await;
+ }
+ // });
}
Ok(())
@@ -884,25 +1198,20 @@ async fn batch_create(
size_counter: &usize,
objects: Vec<UserCollabParams>,
) {
- let ids = objects
- .iter()
- .map(|o| o.object_id.clone())
- .collect::<Vec<_>>()
- .join(", ");
match user_cloud_service
.batch_create_collab_object(workspace_id, objects)
.await
{
Ok(_) => {
info!(
- "Batch creating collab objects success, origin payload size: {}",
+ "[AppflowyData]:Batch creating collab objects success, origin payload size: {}",
size_counter
);
},
Err(err) => {
error!(
- "Batch creating collab objects fail:{}, origin payload size: {}, workspace_id:{}, uid: {}, error: {:?}",
- ids, size_counter, workspace_id, uid,err
+ "[AppflowyData]:Batch creating collab objects fail, origin payload size: {}, workspace_id:{}, uid: {}, error: {:?}",
+ size_counter, workspace_id, uid,err
);
},
}
@@ -919,6 +1228,7 @@ where
PersistenceError: From<R::Error>,
{
load_collab_by_object_ids(uid, collab_read, object_ids)
+ .0
.into_iter()
.filter_map(|(oid, collab)| {
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.rs
index 0fed9cd9d4..76895033b1 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
@@ -1,34 +1,35 @@
use collab::preclude::Collab;
use collab_integrate::{CollabKVAction, PersistenceError};
use std::collections::HashMap;
-use tracing::instrument;
/// This function loads collab objects by their object_ids.
-#[instrument(level = "debug", skip_all)]
pub fn load_collab_by_object_ids<'a, R>(
uid: i64,
collab_read_txn: &R,
object_ids: &[String],
-) -> HashMap<String, Collab>
+) -> (HashMap<String, Collab>, Vec<String>)
where
R: CollabKVAction<'a>,
PersistenceError: From<R::Error>,
{
+ let 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) {
Ok(collab) => {
collab_by_oid.insert(object_id.clone(), collab);
},
- Err(err) => tracing::error!("🔴load collab: {} failed: {:?} ", object_id, err),
+ Err(err) => {
+ invalid_object_ids.push(object_id.clone());
+ tracing::error!("🔴load collab: {} failed: {:?} ", object_id, err)
+ },
}
}
- collab_by_oid
+ (collab_by_oid, invalid_object_ids)
}
/// This function loads single collab object by its object_id.
-#[instrument(level = "debug", skip_all)]
pub fn load_collab_by_object_id<'a, R>(
uid: i64,
collab_read_txn: &R,
diff --git a/frontend/rust-lib/flowy-user/src/services/db.rs b/frontend/rust-lib/flowy-user/src/services/db.rs
index f16d242a96..1050902f2b 100644
--- a/frontend/rust-lib/flowy-user/src/services/db.rs
+++ b/frontend/rust-lib/flowy-user/src/services/db.rs
@@ -44,18 +44,8 @@ impl UserDB {
}
/// Performs a conditional backup or restoration of the collaboration database (CollabDB) for a specific user.
- ///
- /// This function takes a user ID and conducts the following operations:
- ///
- /// **Backup or Restoration**:
- /// - If the CollabDB exists, it tries to open the database:
- /// - **Successful Open**: If the database opens successfully, it attempts to back it up.
- /// - **Failed Open**: If the database cannot be opened, it indicates a potential issue, and the function
- /// attempts to restore the database from the latest backup.
- /// - If the CollabDB does not exist, it immediately attempts to restore from the latest backup.
- ///
#[instrument(level = "debug", skip_all)]
- pub fn backup_or_restore(&self, uid: i64, workspace_id: &str) {
+ pub fn backup(&self, uid: i64, workspace_id: &str) {
// Obtain the path for the collaboration database.
let collab_db_path = self.paths.collab_db_path(uid);
@@ -63,12 +53,10 @@ impl UserDB {
if let Ok(history_folder) = self.paths.collab_db_history(uid, true) {
// Initialize the backup utility for the collaboration database.
let zip_backup = CollabDBZipBackup::new(collab_db_path.clone(), history_folder);
-
if collab_db_path.exists() {
// Validate the existing collaboration database.
let result = self.open_collab_db(collab_db_path, uid);
let is_ok = validate_collab_db(result, uid, workspace_id);
-
if is_ok {
// If database is valid, update the shared map and initiate backup.
// Asynchronous backup operation.
@@ -77,9 +65,6 @@ impl UserDB {
error!("Backup of collab db failed: {:?}", err);
}
});
- } else if let Err(err) = zip_backup.restore_latest_backup() {
- // If validation fails, attempt to restore from the latest backup.
- error!("Restoring collab db failed: {:?}", err);
}
}
}
@@ -96,21 +81,6 @@ impl UserDB {
vec![]
}
- #[instrument(level = "debug", skip_all)]
- pub fn restore_if_need(&self, uid: i64, workspace_id: &str) {
- if let Ok(history_folder) = self.paths.collab_db_history(uid, false) {
- let collab_db_path = self.paths.collab_db_path(uid);
- let result = self.open_collab_db(&collab_db_path, uid);
- let is_ok = validate_collab_db(result, uid, workspace_id);
- if !is_ok {
- let zip_backup = CollabDBZipBackup::new(collab_db_path, history_folder);
- if let Err(err) = zip_backup.restore_latest_backup() {
- error!("restore collab db failed, {:?}", err);
- }
- }
- }
- }
-
/// Close the database connection for the user.
pub(crate) fn close(&self, user_id: i64) -> Result<(), FlowyError> {
if self.sqlite_map.remove(&user_id).is_some() {
@@ -277,8 +247,9 @@ impl CollabDBZipBackup {
Ok(backups)
}
- #[instrument(skip_all, err)]
- pub fn restore_latest_backup(&self) -> io::Result<()> {
+ #[deprecated(note = "This function is deprecated", since = "0.7.1")]
+ #[allow(dead_code)]
+ fn restore_latest_backup(&self) -> io::Result<()> {
let mut latest_zip: Option<(String, PathBuf)> = None;
// When the history folder does not exist, there is no backup to restore
if !self.history_folder.exists() {
diff --git a/frontend/rust-lib/flowy-user/src/services/sqlite_sql/user_sql.rs b/frontend/rust-lib/flowy-user/src/services/sqlite_sql/user_sql.rs
index 6f13e0f40f..6da6f183cb 100644
--- a/frontend/rust-lib/flowy-user/src/services/sqlite_sql/user_sql.rs
+++ b/frontend/rust-lib/flowy-user/src/services/sqlite_sql/user_sql.rs
@@ -15,6 +15,9 @@ use flowy_sqlite::{query_dsl::*, DBConnection, ExpressionMethods};
pub struct UserTable {
pub(crate) id: String,
pub(crate) name: String,
+ #[deprecated(
+ note = "The workspace_id is deprecated, please use the [Session::UserWorkspace] instead"
+ )]
pub(crate) workspace: String,
pub(crate) icon_url: String,
pub(crate) openai_key: String,
@@ -27,13 +30,7 @@ pub struct UserTable {
pub(crate) ai_model: String,
}
-impl UserTable {
- pub fn set_workspace(mut self, workspace: String) -> Self {
- self.workspace = workspace;
- self
- }
-}
-
+#[allow(deprecated)]
impl From<(UserProfile, Authenticator)> for UserTable {
fn from(value: (UserProfile, Authenticator)) -> Self {
let (user_profile, auth_type) = value;
@@ -41,7 +38,8 @@ impl From<(UserProfile, Authenticator)> for UserTable {
UserTable {
id: user_profile.uid.to_string(),
name: user_profile.name,
- workspace: user_profile.workspace_id,
+ #[allow(deprecated)]
+ workspace: "".to_string(),
icon_url: user_profile.icon_url,
openai_key: user_profile.openai_key,
token: user_profile.token,
@@ -64,7 +62,6 @@ impl From<UserTable> for UserProfile {
token: table.token,
icon_url: table.icon_url,
openai_key: table.openai_key,
- workspace_id: table.workspace,
authenticator: Authenticator::from(table.auth_type),
encryption_type: EncryptionType::from_str(&table.encryption_type).unwrap_or_default(),
stability_ai_key: table.stability_ai_key,
diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
index 5adfced1d2..97621f60c0 100644
--- a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
@@ -554,7 +554,7 @@ impl UserManager {
self
.authenticate_user
.database
- .backup_or_restore(session.user_id, &session.user_workspace.id);
+ .backup(session.user_id, &session.user_workspace.id);
}
/// Fetches the user profile for the given user ID.
@@ -873,7 +873,7 @@ pub(crate) fn run_collab_data_migration(
sqlite_pool: Arc<ConnectionPool>,
version: Option<Version>,
) {
- trace!("Run collab data migration: {:?}", version);
+ trace!("[AppflowyData]:Run collab data migration: {:?}", version);
let migrations = collab_migration_list();
match UserLocalDataMigration::new(session.clone(), collab_db, sqlite_pool).run(
migrations,
@@ -882,10 +882,13 @@ pub(crate) fn run_collab_data_migration(
) {
Ok(applied_migrations) => {
if !applied_migrations.is_empty() {
- info!("Did apply migrations: {:?}", applied_migrations);
+ info!(
+ "[AppflowyData]:Did apply migrations: {:?}",
+ applied_migrations
+ );
}
},
- Err(e) => error!("User data migration failed: {:?}", e),
+ Err(e) => error!("[AppflowyData]:User data migration failed: {:?}", e),
}
}
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.rs
index b674019265..7f177b380e 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
@@ -10,7 +10,7 @@ use collab_integrate::CollabKVDB;
use tracing::{error, info, instrument, trace, warn};
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
-use flowy_folder_pub::entities::{AppFlowyData, ImportData};
+use flowy_folder_pub::entities::{ImportFrom, ImportedCollabData, ImportedFolderData};
use flowy_sqlite::schema::user_workspace_table;
use flowy_sqlite::{query_dsl::*, DBConnection, ExpressionMethods};
use flowy_user_pub::entities::{
@@ -63,89 +63,87 @@ impl UserManager {
})
.await??;
- match import_data {
- ImportData::AppFlowyDataFolder { items } => {
- for item in items {
- self
- .upload_appflowy_data_item(&current_session, item)
- .await?;
- }
- },
- }
+ info!(
+ "[AppflowyData]: upload {} document, {} database, {}, rows",
+ import_data.collab_data.document_object_ids.len(),
+ import_data.collab_data.database_object_ids.len(),
+ import_data.collab_data.row_object_ids.len()
+ );
+ self
+ .upload_collab_data(&current_session, import_data.collab_data)
+ .await?;
+
+ self
+ .upload_folder_data(
+ &current_session,
+ &import_data.source,
+ import_data.parent_view_id,
+ import_data.folder_data,
+ )
+ .await?;
+
Ok(())
}
- async fn upload_appflowy_data_item(
+ async fn upload_folder_data(
+ &self,
+ _current_session: &Session,
+ source: &ImportFrom,
+ parent_view_id: Option<String>,
+ folder_data: ImportedFolderData,
+ ) -> Result<(), FlowyError> {
+ let ImportedFolderData {
+ views,
+ orphan_views,
+ database_view_ids_by_database_id,
+ } = folder_data;
+ self
+ .user_workspace_service
+ .import_database_views(database_view_ids_by_database_id)
+ .await?;
+ self
+ .user_workspace_service
+ .import_views(source, views, orphan_views, parent_view_id)
+ .await?;
+
+ Ok(())
+ }
+
+ async fn upload_collab_data(
&self,
current_session: &Session,
- item: AppFlowyData,
+ collab_data: ImportedCollabData,
) -> Result<(), FlowyError> {
- match item {
- AppFlowyData::Folder {
- views,
- database_view_ids_by_database_id,
- } => {
- // Since `async_trait` does not implement `Sync`, and the handler requires `Sync`, we use a
- // channel to synchronize the operation. This approach allows asynchronous trait methods to be compatible
- // with synchronous handler requirements."
- let (tx, rx) = tokio::sync::oneshot::channel();
- let cloned_workspace_service = self.user_workspace_service.clone();
- af_spawn(async move {
- let result = async {
- cloned_workspace_service
- .did_import_database_views(database_view_ids_by_database_id)
- .await?;
- cloned_workspace_service.did_import_views(views).await?;
- Ok::<(), FlowyError>(())
- }
- .await;
- let _ = tx.send(result);
- })
- .await?;
- rx.await??;
- },
- AppFlowyData::CollabObject {
- row_object_ids,
- document_object_ids,
- database_object_ids,
- } => {
- let user = self
- .get_user_profile_from_disk(current_session.user_id)
- .await?;
- let user_collab_db = self
- .get_collab_db(current_session.user_id)?
- .upgrade()
- .ok_or_else(|| FlowyError::internal().with_context("Collab db not found"))?;
-
- let user_id = current_session.user_id;
- let weak_user_collab_db = Arc::downgrade(&user_collab_db);
- let weak_user_cloud_service = self.cloud_services.get_user_service()?;
- match upload_collab_objects_data(
- user_id,
- weak_user_collab_db,
- &user.workspace_id,
- &user.authenticator,
- AppFlowyData::CollabObject {
- row_object_ids,
- document_object_ids,
- database_object_ids,
- },
- weak_user_cloud_service,
- )
- .await
- {
- Ok(_) => info!(
- "Successfully uploaded collab objects data for user:{}",
- user_id
- ),
- Err(err) => {
- error!(
- "Failed to upload collab objects data: {:?} for user:{}",
- err, user_id
- );
- // TODO(nathan): retry uploading the collab objects data.
- },
- }
+ let user = self
+ .get_user_profile_from_disk(current_session.user_id)
+ .await?;
+ let user_collab_db = self
+ .get_collab_db(current_session.user_id)?
+ .upgrade()
+ .ok_or_else(|| FlowyError::internal().with_context("Collab db not found"))?;
+
+ let user_id = current_session.user_id;
+ let weak_user_collab_db = Arc::downgrade(&user_collab_db);
+ let weak_user_cloud_service = self.cloud_services.get_user_service()?;
+ match upload_collab_objects_data(
+ user_id,
+ weak_user_collab_db,
+ &current_session.user_workspace.id,
+ &user.authenticator,
+ collab_data,
+ weak_user_cloud_service,
+ )
+ .await
+ {
+ Ok(_) => info!(
+ "Successfully uploaded collab objects data for user:{}",
+ user_id
+ ),
+ Err(err) => {
+ error!(
+ "Failed to upload collab objects data: {:?} for user:{}",
+ err, user_id
+ );
},
}
Ok(())
@@ -160,6 +158,7 @@ impl UserManager {
imported_session: old_user.session.as_ref().clone(),
imported_collab_db: old_collab_db.clone(),
container_name: None,
+ parent_view_id: None,
source: ImportedSource::AnonUser,
};
self.perform_import(import_context).await?;