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.
This commit is contained in:
@@ -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<void> 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');
|
||||
|
||||
Reference in New Issue
Block a user