瀏覽代碼

Merge pull request #906 from immich-app/dev/reduce-startup-time

reduce app startup time by loading Hive boxes in parallel
Fynn Petersen-Frey 2 年之前
父節點
當前提交
cfa04fadd1
共有 2 個文件被更改,包括 18 次插入15 次删除
  1. 9 9
      mobile/lib/main.dart
  2. 9 6
      mobile/lib/modules/backup/background_service/background.service.dart

+ 9 - 9
mobile/lib/main.dart

@@ -28,17 +28,19 @@ import 'constants/hive_box.dart';
 
 void main() async {
   await Hive.initFlutter();
-
   Hive.registerAdapter(HiveSavedLoginInfoAdapter());
   Hive.registerAdapter(HiveBackupAlbumsAdapter());
   Hive.registerAdapter(HiveDuplicatedAssetsAdapter());
 
-  await Hive.openBox(userInfoBox);
-  await Hive.openBox<HiveSavedLoginInfo>(hiveLoginInfoBox);
-  await Hive.openBox<HiveBackupAlbums>(hiveBackupInfoBox);
-  await Hive.openBox(hiveGithubReleaseInfoBox);
-  await Hive.openBox(userSettingInfoBox);
-  await Hive.openBox<HiveDuplicatedAssets>(duplicatedAssetsBox);
+  await Future.wait([
+    Hive.openBox(userInfoBox),
+    Hive.openBox<HiveSavedLoginInfo>(hiveLoginInfoBox),
+    Hive.openBox<HiveBackupAlbums>(hiveBackupInfoBox),
+    Hive.openBox(hiveGithubReleaseInfoBox),
+    Hive.openBox(userSettingInfoBox),
+    Hive.openBox<HiveDuplicatedAssets>(duplicatedAssetsBox),
+    EasyLocalization.ensureInitialized(),
+  ]);
 
   SystemChrome.setSystemUIOverlayStyle(
     const SystemUiOverlayStyle(
@@ -46,8 +48,6 @@ void main() async {
     ),
   );
 
-  await EasyLocalization.ensureInitialized();
-
   if (kReleaseMode && Platform.isAndroid) {
     try {
       await FlutterDisplayMode.setHighRefreshRate();

+ 9 - 6
mobile/lib/modules/backup/background_service/background.service.dart

@@ -319,11 +319,14 @@ class BackgroundService {
     Hive.registerAdapter(HiveBackupAlbumsAdapter());
     Hive.registerAdapter(HiveDuplicatedAssetsAdapter());
 
-    await Hive.openBox(userInfoBox);
-    await Hive.openBox<HiveSavedLoginInfo>(hiveLoginInfoBox);
-    await Hive.openBox(userSettingInfoBox);
-    await Hive.openBox(backgroundBackupInfoBox);
-    await Hive.openBox<HiveDuplicatedAssets>(duplicatedAssetsBox);
+    await Future.wait([
+      Hive.openBox(userInfoBox),
+      Hive.openBox<HiveSavedLoginInfo>(hiveLoginInfoBox),
+      Hive.openBox(userSettingInfoBox),
+      Hive.openBox(backgroundBackupInfoBox),
+      Hive.openBox<HiveDuplicatedAssets>(duplicatedAssetsBox),
+      Hive.openBox<HiveBackupAlbums>(hiveBackupInfoBox),
+    ]);
 
     ApiService apiService = ApiService();
     apiService.setEndpoint(Hive.box(userInfoBox).get(serverEndpointKey));
@@ -332,7 +335,7 @@ class BackgroundService {
     AppSettingsService settingsService = AppSettingsService();
 
     final Box<HiveBackupAlbums> box =
-        await Hive.openBox<HiveBackupAlbums>(hiveBackupInfoBox);
+        Hive.box<HiveBackupAlbums>(hiveBackupInfoBox);
     final HiveBackupAlbums? backupAlbumInfo = box.get(backupInfoKey);
     if (backupAlbumInfo == null) {
       return true;