From 968c02940fc61f38c7b306e73831b0e0f9048912 Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Sat, 11 Oct 2025 12:44:35 +0530 Subject: [PATCH] refactor: optimize application startup sequence and migration handling - Removed the immediate initialization of SelfSignedCertificateManager to improve the app's first paint performance. - Introduced lazy initialization of the certificate manager after the first frame, enhancing startup efficiency. - Implemented a fast path for migration checks in PersistenceMigrator to skip unnecessary operations if already completed in the current session, improving overall performance during app startup. - Updated comments for clarity on the changes made to the startup sequence and migration process. --- lib/core/persistence/persistence_migrator.dart | 8 ++++++++ lib/main.dart | 11 ++++++++--- openwebui-src | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/core/persistence/persistence_migrator.dart b/lib/core/persistence/persistence_migrator.dart index 200828a..be414bc 100644 --- a/lib/core/persistence/persistence_migrator.dart +++ b/lib/core/persistence/persistence_migrator.dart @@ -11,13 +11,20 @@ class PersistenceMigrator { PersistenceMigrator({required HiveBoxes hiveBoxes}) : _boxes = hiveBoxes; static const int _targetVersion = 1; + static bool _migrationComplete = false; final HiveBoxes _boxes; Future migrateIfNeeded() async { + // Fast path: if we already checked migration in this app session, skip + if (_migrationComplete) { + return; + } + final currentVersion = _boxes.metadata.get(HiveStoreKeys.migrationVersion) as int?; if (currentVersion != null && currentVersion >= _targetVersion) { + _migrationComplete = true; return; } @@ -34,6 +41,7 @@ class PersistenceMigrator { await _migrateTaskQueue(prefs); await _boxes.metadata.put(HiveStoreKeys.migrationVersion, _targetVersion); + _migrationComplete = true; await _cleanupLegacyKeys(prefs); DebugLogger.log('Migration completed', scope: 'persistence/migration'); diff --git a/lib/main.dart b/lib/main.dart index fab5f1f..3ceb824 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -29,8 +29,6 @@ void main() { () async { WidgetsFlutterBinding.ensureInitialized(); - SelfSignedCertificateManager.instance.ensureInitialized(); - // Global error handlers FlutterError.onError = (FlutterErrorDetails details) { DebugLogger.error( @@ -59,11 +57,16 @@ void main() { _startupTimeline!.start('app_startup'); _startupTimeline!.instant('bindings_initialized'); - // Defer edge-to-edge mode to post-frame to avoid impacting first paint + // Defer edge-to-edge mode and certificate manager to post-frame to avoid + // impacting first paint WidgetsBinding.instance.addPostFrameCallback((_) { // ignore: discarded_futures SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); _startupTimeline?.instant('edge_to_edge_enabled'); + + // Initialize certificate manager lazily after first frame + SelfSignedCertificateManager.instance.ensureInitialized(); + _startupTimeline?.instant('cert_manager_ready'); }); const secureStorage = FlutterSecureStorage( @@ -80,9 +83,11 @@ void main() { ); _startupTimeline!.instant('secure_storage_ready'); + // Initialize Hive (now optimized with migration state caching) final hiveBoxes = await HiveBootstrap.instance.ensureInitialized(); _startupTimeline!.instant('hive_ready'); + // Run migration check (now fast-pathed after first run) final migrator = PersistenceMigrator(hiveBoxes: hiveBoxes); await migrator.migrateIfNeeded(); _startupTimeline!.instant('migration_complete'); diff --git a/openwebui-src b/openwebui-src index 46ae3f4..43a2881 160000 --- a/openwebui-src +++ b/openwebui-src @@ -1 +1 @@ -Subproject commit 46ae3f4f5d7d4d706041bdae4ad2d802e568712b +Subproject commit 43a28810741c9e02b72c50840d7bb0d876e81aa5