High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
chore: do not optimize on cleanup (#29118)
shenlong0f49bcbd2718
diff --git a/mobile/lib/domain/services/background_worker.service.dart b/mobile/lib/domain/services/background_worker.service.dartindex 529ec770c4..d490b226c7 100644--- a/mobile/lib/domain/services/background_worker.service.dart+++ b/mobile/lib/domain/services/background_worker.service.dart@@ -104,6 +104,7 @@ class BackgroundWorkerBgService extends BackgroundWorkerFlutterApi {Future<void> onAndroidUpload(int? maxMinutes) async {final hashTimeout = Duration(minutes: _isBackupEnabled ? 3 : 6);final backupTimeout = maxMinutes != null ? Duration(minutes: maxMinutes - 1) : null;+ await _optimizeDB();return _backgroundLoop(hashTimeout: hashTimeout,backupTimeout: backupTimeout,@@ -123,6 +124,11 @@ class BackgroundWorkerBgService extends BackgroundWorkerFlutterApi {return;}+ // Only for Background Processing tasks+ if (maxSeconds == null) {+ await _optimizeDB();+ }+// Run sync local, sync remote, hash and backup concurrently so the bg// refresh task (20s budget) can make progress on all four instead of// racing them sequentially. Phases are independent at the data layer:@@ -193,6 +199,14 @@ class BackgroundWorkerBgService extends BackgroundWorkerFlutterApi {}}+ Future<void> _optimizeDB() async {+ try {+ await (_drift.optimize(allTables: true), _driftLogger.optimize()).wait;+ } catch (error, stack) {+ dPrint(() => "Error during background worker optimize: $error, $stack");+ }+ }+Future<void> _cleanup() async {await runZonedGuarded(_handleCleanup, (error, stack) {dPrint(() => "Error during background worker cleanup: $error, $stack");@@ -221,7 +235,7 @@ class BackgroundWorkerBgService extends BackgroundWorkerFlutterApi {if (nativeSyncApi != null) nativeSyncApi.cancelHashing(),]);await workerManagerPatch.dispose().catchError((_) async {});- await Future.wait([LogService.I.dispose(), Store.dispose(), _drift.optimize(allTables: true)]);+ await Future.wait([LogService.I.dispose(), Store.dispose()]);await _drift.close();await _driftLogger.close();diff --git a/mobile/lib/infrastructure/repositories/logger_db.repository.dart b/mobile/lib/infrastructure/repositories/logger_db.repository.dartindex 32af4af748..8d9794ac8b 100644--- a/mobile/lib/infrastructure/repositories/logger_db.repository.dart+++ b/mobile/lib/infrastructure/repositories/logger_db.repository.dart@@ -2,6 +2,7 @@ import 'package:drift/drift.dart';import 'package:drift_sqlite_async/drift_sqlite_async.dart';import 'package:immich_mobile/infrastructure/entities/log.entity.dart';import 'package:immich_mobile/infrastructure/repositories/logger_db.repository.drift.dart';+import 'package:immich_mobile/utils/debug_print.dart';import 'package:sqlite_async/sqlite_async.dart';@DriftDatabase(tables: [LogMessageEntity])@@ -13,6 +14,14 @@ class DriftLogger extends $DriftLogger {@overrideint get schemaVersion => 1;+ Future<void> optimize() async {+ try {+ await customStatement('PRAGMA optimize=0x10002');+ } catch (error) {+ dPrint(() => 'Failed to optimize logger database: $error');+ }+ }+@overrideMigrationStrategy get migration => MigrationStrategy(beforeOpen: (details) async {