Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Share sqlite_async open and migration lifecycle

laurenspriemdfbca391bd99
diff --git a/mobile/apps/photos/lib/db/collections_db.dart b/mobile/apps/photos/lib/db/collections_db.dart
index f87e4aa1da..c7af19972e 100644
--- a/mobile/apps/photos/lib/db/collections_db.dart
+++ b/mobile/apps/photos/lib/db/collections_db.dart
@@ -1,8 +1,5 @@
import 'dart:convert';
-import 'dart:io';
-import 'package:path/path.dart';
-import 'package:path_provider/path_provider.dart';
import 'package:photos/db/common/base.dart';
import "package:photos/gateways/collections/models/public_url.dart";
import "package:photos/models/api/collection/user.dart";
@@ -60,33 +57,12 @@ class CollectionsDB with SqlDbBase {
static final CollectionsDB instance = CollectionsDB._privateConstructor();
- static Future<SqliteDatabase>? _dbFuture;
-
- Future<SqliteDatabase> get database async {
- final databaseFuture = _dbFuture ??= _initDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_dbFuture, databaseFuture)) {
- _dbFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initDatabase() async {
- final Directory documentsDirectory =
- await getApplicationDocumentsDirectory();
- final String path = join(documentsDirectory.path, _databaseName);
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, [...intitialScript, ...migrationScripts]);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ Future<SqliteDatabase> get database => getOrOpenDatabase(
+ () => openMigratedDatabase(_databaseName, [
+ ...intitialScript,
+ ...migrationScripts,
+ ]),
+ );
Future<void> clearTable() async {
final db = await instance.database;
@@ -276,7 +252,7 @@ class CollectionsDB with SqlDbBase {
$columnIsDeleted, $columnMMdVersion, $columnMMdEncodedJson,
$columnPubMMdVersion, $columnPubMMdEncodedJson,
$columnSharedMMdVersion, $columnSharedMMdJson
- ) VALUES (${List.filled(22, '?').join(', ')})
+ ) VALUES (${SqlDbBase.getParams(22)})
''', parameterSets);
}
diff --git a/mobile/apps/photos/lib/db/common/base.dart b/mobile/apps/photos/lib/db/common/base.dart
index 7fd5f3e544..01436b793b 100644
--- a/mobile/apps/photos/lib/db/common/base.dart
+++ b/mobile/apps/photos/lib/db/common/base.dart
@@ -1,10 +1,14 @@
import "package:flutter/foundation.dart";
+import "package:path/path.dart";
+import "package:path_provider/path_provider.dart";
import "package:sqlite_async/sqlite3_common.dart";
import "package:sqlite_async/sqlite_async.dart";
mixin SqlDbBase {
static final Map<int, String> _params = <int, String>{};
+ Future<SqliteDatabase>? _dbFuture;
+
static String getParams(int count) {
if (count <= 0) {
throw ArgumentError.value(count, "count", "must be greater than 0");
@@ -12,6 +16,45 @@ mixin SqlDbBase {
return _params.putIfAbsent(count, () => List.filled(count, "?").join(", "));
}
+ Future<SqliteDatabase> getOrOpenDatabase(
+ Future<SqliteDatabase> Function() openDatabase,
+ ) async {
+ final future = _dbFuture ??= openDatabase();
+ try {
+ return await future;
+ } catch (_) {
+ if (identical(_dbFuture, future)) {
+ _dbFuture = null;
+ }
+ rethrow;
+ }
+ }
+
+ @protected
+ void resetDatabaseFuture() {
+ _dbFuture = null;
+ }
+
+ Future<SqliteDatabase> openMigratedDatabase(
+ String dbName,
+ List<String> migrationScripts, {
+ void Function(String path)? logPath,
+ }) async {
+ final documentsDirectory = await getApplicationDocumentsDirectory();
+ final String path = join(documentsDirectory.path, dbName);
+ logPath?.call(path);
+ final database = SqliteDatabase(path: path);
+ try {
+ await migrate(database, migrationScripts);
+ return database;
+ } catch (_) {
+ try {
+ await database.close();
+ } catch (_) {}
+ rethrow;
+ }
+ }
+
Future<void> migrate(
SqliteDatabase database,
List<String> migrationScripts,
diff --git a/mobile/apps/photos/lib/db/file_updation_db.dart b/mobile/apps/photos/lib/db/file_updation_db.dart
index d6e94ad30c..cc9aa4a114 100644
--- a/mobile/apps/photos/lib/db/file_updation_db.dart
+++ b/mobile/apps/photos/lib/db/file_updation_db.dart
@@ -1,9 +1,5 @@
-import 'dart:io';
-
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
-import 'package:path/path.dart';
-import 'package:path_provider/path_provider.dart';
import 'package:photos/db/common/base.dart';
import 'package:sqlite_async/sqlite_async.dart';
@@ -46,34 +42,12 @@ class FileUpdationDB with SqlDbBase {
static final FileUpdationDB instance = FileUpdationDB._privateConstructor();
- static Future<SqliteDatabase>? _dbFuture;
-
- Future<SqliteDatabase> get database async {
- final databaseFuture = _dbFuture ??= _initDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_dbFuture, databaseFuture)) {
- _dbFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initDatabase() async {
- final Directory documentsDirectory =
- await getApplicationDocumentsDirectory();
- final String path = join(documentsDirectory.path, _databaseName);
- debugPrint("DB path " + path);
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, [...initializationScript, ...migrationScripts]);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ Future<SqliteDatabase> get database => getOrOpenDatabase(
+ () => openMigratedDatabase(_databaseName, [
+ ...initializationScript,
+ ...migrationScripts,
+ ], logPath: (path) => debugPrint("DB path " + path)),
+ );
Future<void> clearTable() async {
final db = await instance.database;
diff --git a/mobile/apps/photos/lib/db/files_db.dart b/mobile/apps/photos/lib/db/files_db.dart
index 2fa8654236..e1992f12ea 100644
--- a/mobile/apps/photos/lib/db/files_db.dart
+++ b/mobile/apps/photos/lib/db/files_db.dart
@@ -126,34 +126,13 @@ class FilesDB with SqlDbBase {
static final FilesDB instance = FilesDB._privateConstructor();
- static Future<SqliteDatabase>? _sqliteAsyncDBFuture;
-
- Future<SqliteDatabase> get sqliteAsyncDB async {
- final databaseFuture = _sqliteAsyncDBFuture ??= _initSqliteAsyncDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_sqliteAsyncDBFuture, databaseFuture)) {
- _sqliteAsyncDBFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initSqliteAsyncDatabase() async {
- final Directory documentsDirectory =
- await getApplicationDocumentsDirectory();
- final String path = join(documentsDirectory.path, _databaseName);
- _logger.info("DB path " + path);
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, _migrationScripts);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ Future<SqliteDatabase> get sqliteAsyncDB => getOrOpenDatabase(
+ () => openMigratedDatabase(
+ _databaseName,
+ _migrationScripts,
+ logPath: (path) => _logger.info("DB path " + path),
+ ),
+ );
static List<String> createTable(String tableName) {
return [
@@ -435,7 +414,7 @@ class FilesDB with SqlDbBase {
await getApplicationDocumentsDirectory();
final String path = join(documentsDirectory.path, _databaseName);
File(path).deleteSync(recursive: true);
- _sqliteAsyncDBFuture = null;
+ resetDatabaseFuture();
}
}
diff --git a/mobile/apps/photos/lib/db/gallery_downloads_db.dart b/mobile/apps/photos/lib/db/gallery_downloads_db.dart
index b057d6f6ee..b77216dec6 100644
--- a/mobile/apps/photos/lib/db/gallery_downloads_db.dart
+++ b/mobile/apps/photos/lib/db/gallery_downloads_db.dart
@@ -1,6 +1,4 @@
import "package:logging/logging.dart";
-import "package:path/path.dart";
-import "package:path_provider/path_provider.dart";
import "package:photos/db/common/base.dart";
import "package:photos/module/download/task.dart";
import "package:sqlite_async/sqlite_async.dart";
@@ -50,33 +48,13 @@ class GalleryDownloadsDB with SqlDbBase {
static final GalleryDownloadsDB instance =
GalleryDownloadsDB._privateConstructor();
- static Future<SqliteDatabase>? _sqliteAsyncDBFuture;
-
- Future<SqliteDatabase> get sqliteAsyncDB async {
- final databaseFuture = _sqliteAsyncDBFuture ??= _initSqliteAsyncDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_sqliteAsyncDBFuture, databaseFuture)) {
- _sqliteAsyncDBFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initSqliteAsyncDatabase() async {
- final documentsDirectory = await getApplicationDocumentsDirectory();
- final path = join(documentsDirectory.path, _databaseName);
- _logger.info("DB path $path");
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, _migrationScripts);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ Future<SqliteDatabase> get sqliteAsyncDB => getOrOpenDatabase(
+ () => openMigratedDatabase(
+ _databaseName,
+ _migrationScripts,
+ logPath: (path) => _logger.info("DB path $path"),
+ ),
+ );
Future<void> upsertTask(DownloadTask task) async {
final db = await sqliteAsyncDB;
diff --git a/mobile/apps/photos/lib/db/ignored_files_db.dart b/mobile/apps/photos/lib/db/ignored_files_db.dart
index 01dcf7fde9..90b35909af 100644
--- a/mobile/apps/photos/lib/db/ignored_files_db.dart
+++ b/mobile/apps/photos/lib/db/ignored_files_db.dart
@@ -1,8 +1,6 @@
import 'dart:io';
import 'package:logging/logging.dart';
-import 'package:path/path.dart';
-import 'package:path_provider/path_provider.dart';
import 'package:photos/db/common/base.dart';
import 'package:photos/models/ignored_file.dart';
import 'package:sqlite_async/sqlite_async.dart';
@@ -36,33 +34,9 @@ class IgnoredFilesDB with SqlDbBase {
static final IgnoredFilesDB instance = IgnoredFilesDB._privateConstructor();
- static Future<SqliteDatabase>? _dbFuture;
-
- Future<SqliteDatabase> get database async {
- final databaseFuture = _dbFuture ??= _initDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_dbFuture, databaseFuture)) {
- _dbFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initDatabase() async {
- final Directory documentsDirectory =
- await getApplicationDocumentsDirectory();
- final String path = join(documentsDirectory.path, _databaseName);
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, _migrationScripts);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ Future<SqliteDatabase> get database => getOrOpenDatabase(
+ () => openMigratedDatabase(_databaseName, _migrationScripts),
+ );
Future<void> clearTable() async {
final db = await instance.database;
diff --git a/mobile/apps/photos/lib/db/memories_db.dart b/mobile/apps/photos/lib/db/memories_db.dart
index 26c0381b1e..6fa0fd09e3 100644
--- a/mobile/apps/photos/lib/db/memories_db.dart
+++ b/mobile/apps/photos/lib/db/memories_db.dart
@@ -1,8 +1,5 @@
import 'dart:async';
-import 'dart:io';
-import 'package:path/path.dart';
-import 'package:path_provider/path_provider.dart';
import 'package:photos/db/common/base.dart';
import 'package:photos/models/memories/memory.dart';
import 'package:sqlite_async/sqlite_async.dart';
@@ -15,6 +12,15 @@ class MemoriesDB with SqlDbBase {
static const columnFileID = 'file_id';
static const columnSeenTime = 'seen_time';
+ static const _migrationScripts = [
+ '''
+ CREATE TABLE $table (
+ $columnFileID INTEGER PRIMARY KEY NOT NULL,
+ $columnSeenTime TEXT NOT NULL
+ )
+ ''',
+ ];
+
final String _dbName;
MemoriesDB._privateConstructor({String dbName = _databaseName})
@@ -24,39 +30,8 @@ class MemoriesDB with SqlDbBase {
dbName: "ente.memories.offline.db",
);
- Future<SqliteDatabase>? _dbFuture;
- Future<SqliteDatabase> get database async {
- final databaseFuture = _dbFuture ??= _initDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_dbFuture, databaseFuture)) {
- _dbFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initDatabase() async {
- final Directory documentsDirectory =
- await getApplicationDocumentsDirectory();
- final String path = join(documentsDirectory.path, _dbName);
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, [
- '''
- CREATE TABLE $table (
- $columnFileID INTEGER PRIMARY KEY NOT NULL,
- $columnSeenTime TEXT NOT NULL
- )
- ''',
- ]);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ Future<SqliteDatabase> get database =>
+ getOrOpenDatabase(() => openMigratedDatabase(_dbName, _migrationScripts));
Future<void> clearTable() async {
final db = await database;
diff --git a/mobile/apps/photos/lib/db/memory_shares_db.dart b/mobile/apps/photos/lib/db/memory_shares_db.dart
index f6a0785969..50ec28a5ac 100644
--- a/mobile/apps/photos/lib/db/memory_shares_db.dart
+++ b/mobile/apps/photos/lib/db/memory_shares_db.dart
@@ -1,7 +1,3 @@
-import 'dart:io';
-
-import 'package:path/path.dart';
-import 'package:path_provider/path_provider.dart';
import 'package:photos/db/common/base.dart';
import 'package:photos/models/api/memory_share/memory_share.dart';
import 'package:sqlite_async/sqlite_async.dart';
@@ -26,31 +22,8 @@ class MemorySharesDB with SqlDbBase {
static const _columnPreviewUploadedFileID = 'preview_uploaded_file_id';
static const _columnFileCount = 'file_count';
- MemorySharesDB._();
- static final MemorySharesDB instance = MemorySharesDB._();
-
- static Future<SqliteDatabase>? _dbFuture;
-
- Future<SqliteDatabase> get database async {
- final databaseFuture = _dbFuture ??= _initDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_dbFuture, databaseFuture)) {
- _dbFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initDatabase() async {
- final Directory documentsDirectory =
- await getApplicationDocumentsDirectory();
- final String path = join(documentsDirectory.path, _databaseName);
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, [
- '''
+ static const _migrationScripts = [
+ '''
CREATE TABLE $_table (
$_columnID INTEGER PRIMARY KEY NOT NULL,
$_columnType TEXT NOT NULL,
@@ -68,13 +41,14 @@ class MemorySharesDB with SqlDbBase {
$_columnFileCount INTEGER
)
''',
- ]);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ ];
+
+ MemorySharesDB._();
+ static final MemorySharesDB instance = MemorySharesDB._();
+
+ Future<SqliteDatabase> get database => getOrOpenDatabase(
+ () => openMigratedDatabase(_databaseName, _migrationScripts),
+ );
Future<void> upsert(MemoryShare share) async {
final db = await database;
@@ -85,7 +59,7 @@ class MemorySharesDB with SqlDbBase {
$_columnMemKeyDecryptionNonce, $_columnAccessToken,
$_columnIsDeleted, $_columnCreatedAt, $_columnUpdatedAt, $_columnUrl,
$_columnMemoryHash, $_columnPreviewUploadedFileID, $_columnFileCount
- ) VALUES (${List.filled(14, '?').join(', ')})
+ ) VALUES (${SqlDbBase.getParams(14)})
''', _toParameters(share));
}
diff --git a/mobile/apps/photos/lib/db/ml/db.dart b/mobile/apps/photos/lib/db/ml/db.dart
index 9f2fb45c19..b194bacefb 100644
--- a/mobile/apps/photos/lib/db/ml/db.dart
+++ b/mobile/apps/photos/lib/db/ml/db.dart
@@ -101,19 +101,8 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
..._defaultMigrationScripts,
];
- Future<SqliteDatabase>? _sqliteAsyncDBFuture;
-
- Future<SqliteDatabase> get asyncDB async {
- final databaseFuture = _sqliteAsyncDBFuture ??= _initSqliteAsyncDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_sqliteAsyncDBFuture, databaseFuture)) {
- _sqliteAsyncDBFuture = null;
- }
- rethrow;
- }
- }
+ Future<SqliteDatabase> get asyncDB =>
+ getOrOpenDatabase(_initSqliteAsyncDatabase);
Future<SqliteDatabase> _initSqliteAsyncDatabase() async {
final documentsDirectory = await getApplicationDocumentsDirectory();
diff --git a/mobile/apps/photos/lib/db/social_db.dart b/mobile/apps/photos/lib/db/social_db.dart
index f08b65e6a7..722f9088d3 100644
--- a/mobile/apps/photos/lib/db/social_db.dart
+++ b/mobile/apps/photos/lib/db/social_db.dart
@@ -1,10 +1,7 @@
import 'dart:async';
-import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
-import 'package:path/path.dart';
-import 'package:path_provider/path_provider.dart';
import 'package:photos/db/common/base.dart';
import 'package:photos/models/social/anon_profile.dart';
import 'package:photos/models/social/comment.dart';
@@ -95,34 +92,13 @@ class SocialDB with SqlDbBase {
SocialDB._();
static final SocialDB instance = SocialDB._();
- static Future<SqliteDatabase>? _dbFuture;
-
- Future<SqliteDatabase> get database async {
- final databaseFuture = _dbFuture ??= _initDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_dbFuture, databaseFuture)) {
- _dbFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initDatabase() async {
- final Directory documentsDirectory =
- await getApplicationDocumentsDirectory();
- final String path = join(documentsDirectory.path, _databaseName);
- _logger.info("DB path: $path");
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, _migrationScripts);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ Future<SqliteDatabase> get database => getOrOpenDatabase(
+ () => openMigratedDatabase(
+ _databaseName,
+ _migrationScripts,
+ logPath: (path) => _logger.info("DB path: $path"),
+ ),
+ );
Future<void> addComment(Comment comment) async {
final db = await database;
diff --git a/mobile/apps/photos/lib/db/trash_db.dart b/mobile/apps/photos/lib/db/trash_db.dart
index 235bc2830b..724cc23768 100644
--- a/mobile/apps/photos/lib/db/trash_db.dart
+++ b/mobile/apps/photos/lib/db/trash_db.dart
@@ -1,9 +1,6 @@
import 'dart:convert';
-import 'dart:io';
import 'package:logging/logging.dart';
-import 'package:path/path.dart';
-import 'package:path_provider/path_provider.dart';
import 'package:photos/db/common/base.dart';
import 'package:photos/models/file/trash_file.dart';
import 'package:photos/models/file_load_result.dart';
@@ -70,34 +67,13 @@ class TrashDB with SqlDbBase {
static final TrashDB instance = TrashDB._privateConstructor();
- static Future<SqliteDatabase>? _dbFuture;
-
- Future<SqliteDatabase> get database async {
- final databaseFuture = _dbFuture ??= _initDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_dbFuture, databaseFuture)) {
- _dbFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initDatabase() async {
- final Directory documentsDirectory =
- await getApplicationDocumentsDirectory();
- final String path = join(documentsDirectory.path, _databaseName);
- _logger.info("DB path " + path);
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, _migrationScripts);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ Future<SqliteDatabase> get database => getOrOpenDatabase(
+ () => openMigratedDatabase(
+ _databaseName,
+ _migrationScripts,
+ logPath: (path) => _logger.info("DB path " + path),
+ ),
+ );
Future<void> clearTable() async {
final db = await instance.database;
@@ -270,7 +246,7 @@ class TrashDB with SqlDbBase {
$columnLocalID, $columnCreationTime, $columnFileMetadata,
$columnMMdVersion, $columnMMdEncodedJson, $columnPubMMdVersion,
$columnPubMMdEncodedJson
- ) VALUES (${List.filled(18, '?').join(', ')})
+ ) VALUES (${SqlDbBase.getParams(18)})
''', parameterSets);
}
diff --git a/mobile/apps/photos/lib/db/upload_locks_db.dart b/mobile/apps/photos/lib/db/upload_locks_db.dart
index 5160756439..b2864354c1 100644
--- a/mobile/apps/photos/lib/db/upload_locks_db.dart
+++ b/mobile/apps/photos/lib/db/upload_locks_db.dart
@@ -1,9 +1,6 @@
import 'dart:async';
import 'dart:convert';
-import 'dart:io';
-import 'package:path/path.dart';
-import 'package:path_provider/path_provider.dart';
import "package:photos/core/errors.dart";
import 'package:photos/db/common/base.dart';
import "package:photos/module/upload/model/multipart.dart";
@@ -87,33 +84,12 @@ class UploadLocksDB with SqlDbBase {
UploadLocksDB._privateConstructor();
static final UploadLocksDB instance = UploadLocksDB._privateConstructor();
- static Future<SqliteDatabase>? _dbFuture;
- Future<SqliteDatabase> get database async {
- final databaseFuture = _dbFuture ??= _initDatabase();
- try {
- return await databaseFuture;
- } catch (_) {
- if (identical(_dbFuture, databaseFuture)) {
- _dbFuture = null;
- }
- rethrow;
- }
- }
-
- Future<SqliteDatabase> _initDatabase() async {
- final Directory documentsDirectory =
- await getApplicationDocumentsDirectory();
- final String path = join(documentsDirectory.path, _databaseName);
-
- final database = SqliteDatabase(path: path);
- try {
- await migrate(database, [...initializationScript, ...migrationScripts]);
- return database;
- } catch (_) {
- await database.close();
- rethrow;
- }
- }
+ Future<SqliteDatabase> get database => getOrOpenDatabase(
+ () => openMigratedDatabase(_databaseName, [
+ ...initializationScript,
+ ...migrationScripts,
+ ]),
+ );
static List<String> _createUploadLocksTable() {
return [
diff --git a/mobile/packages/contacts/lib/src/db/contacts_database.dart b/mobile/packages/contacts/lib/src/db/contacts_database.dart
index 9a0e9cfbad..5ca9ed50d8 100644
--- a/mobile/packages/contacts/lib/src/db/contacts_database.dart
+++ b/mobile/packages/contacts/lib/src/db/contacts_database.dart
@@ -31,14 +31,8 @@ class ContactsDatabase {
if (_configuredUserId == userId && _dbFuture != null) {
return;
}
- final previousDatabaseFuture = _dbFuture;
- _dbFuture = null;
+ await close();
_configuredUserId = userId;
- if (previousDatabaseFuture != null) {
- try {
- await (await previousDatabaseFuture).close();
- } catch (_) {}
- }
}
Future<void> close() async {