From 4a6c3379608fa3118107746e53c3859516dd51b3 Mon Sep 17 00:00:00 2001 From: Fynn Petersen-Frey Date: Mon, 31 Oct 2022 15:38:24 +0100 Subject: [PATCH] reduce app startup time by loading Hive boxes in parallel --- mobile/lib/main.dart | 18 +++++++++--------- .../background_service/background.service.dart | 15 +++++++++------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart index c68ec501d0..bacd9bb42d 100644 --- a/mobile/lib/main.dart +++ b/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(hiveLoginInfoBox); - await Hive.openBox(hiveBackupInfoBox); - await Hive.openBox(hiveGithubReleaseInfoBox); - await Hive.openBox(userSettingInfoBox); - await Hive.openBox(duplicatedAssetsBox); + await Future.wait([ + Hive.openBox(userInfoBox), + Hive.openBox(hiveLoginInfoBox), + Hive.openBox(hiveBackupInfoBox), + Hive.openBox(hiveGithubReleaseInfoBox), + Hive.openBox(userSettingInfoBox), + Hive.openBox(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(); diff --git a/mobile/lib/modules/backup/background_service/background.service.dart b/mobile/lib/modules/backup/background_service/background.service.dart index c4ecfb4fce..be0f3991e9 100644 --- a/mobile/lib/modules/backup/background_service/background.service.dart +++ b/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(hiveLoginInfoBox); - await Hive.openBox(userSettingInfoBox); - await Hive.openBox(backgroundBackupInfoBox); - await Hive.openBox(duplicatedAssetsBox); + await Future.wait([ + Hive.openBox(userInfoBox), + Hive.openBox(hiveLoginInfoBox), + Hive.openBox(userSettingInfoBox), + Hive.openBox(backgroundBackupInfoBox), + Hive.openBox(duplicatedAssetsBox), + Hive.openBox(hiveBackupInfoBox), + ]); ApiService apiService = ApiService(); apiService.setEndpoint(Hive.box(userInfoBox).get(serverEndpointKey)); @@ -332,7 +335,7 @@ class BackgroundService { AppSettingsService settingsService = AppSettingsService(); final Box box = - await Hive.openBox(hiveBackupInfoBox); + Hive.box(hiveBackupInfoBox); final HiveBackupAlbums? backupAlbumInfo = box.get(backupInfoKey); if (backupAlbumInfo == null) { return true;