Skip to content

Commit 80c8e4d

Browse files
committed
refactor: cache AppDatabase and add common dependency disposal
- Keep a shared AppDatabase instance in the call isolate to reuse across repositories. - Add _disposeCommonDependencies() to close DB/isolate managers and reset cached singletons. - Release resources via _disposeCommonDependencies() on push sync releaseResources callback.
1 parent ab7c002 commit 80c8e4d

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

lib/features/call/services/services_isolate.dart

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SecureStorage? _secureStorage;
2424
AppCertificates? _appCertificates;
2525
AppInfo? _appInfo;
2626
AppMetadataProvider? _appLabelsProvider;
27+
AppDatabase? _appDatabase;
2728

2829
CallLogsRepository? _callLogsRepository;
2930

@@ -41,9 +42,26 @@ Future<void> _initializeCommonDependencies() async {
4142
_appLogger ??= await AppLogger.init(_remoteConfigService!, _appLabelsProvider!);
4243
_appCertificates ??= await AppCertificates.init();
4344

44-
_callLogsRepository ??= CallLogsRepository(
45-
appDatabase: IsolateDatabase.create(directoryPath: _appPath!.applicationDocumentsPath),
46-
);
45+
_appDatabase ??= IsolateDatabase.create(directoryPath: _appPath!.applicationDocumentsPath);
46+
_callLogsRepository ??= CallLogsRepository(appDatabase: _appDatabase!);
47+
}
48+
49+
Future<void> _disposeCommonDependencies() async {
50+
await _pushNotificationIsolateManager?.close();
51+
await _appDatabase?.close();
52+
53+
_appDatabase = null;
54+
_pushNotificationIsolateManager = null;
55+
_callLogsRepository = null;
56+
_remoteConfigService = null;
57+
_appPath = null;
58+
_deviceInfo = null;
59+
_packageInfo = null;
60+
_appLogger = null;
61+
_secureStorage = null;
62+
_appCertificates = null;
63+
_appInfo = null;
64+
_appLabelsProvider = null;
4765
}
4866

4967
Future<void> _initializeSignalingDependencies() async {
@@ -78,7 +96,7 @@ Future<void> onPushNotificationSyncCallback(CallkeepPushNotificationSyncStatus s
7896
case CallkeepPushNotificationSyncStatus.synchronizeCallStatus:
7997
await _pushNotificationIsolateManager?.sync();
8098
case CallkeepPushNotificationSyncStatus.releaseResources:
81-
await _pushNotificationIsolateManager?.close();
99+
await _disposeCommonDependencies();
82100
}
83101
}
84102

0 commit comments

Comments
 (0)