Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Use sqlite_async instead of sqlite3 (#1489)

Ashilc4c513a1d7c2
diff --git a/mobile/lib/db/files_db.dart b/mobile/lib/db/files_db.dart
index 2fe4f5db60..51323bf2a2 100644
--- a/mobile/lib/db/files_db.dart
+++ b/mobile/lib/db/files_db.dart
@@ -106,6 +106,7 @@ class FilesDB {
static Future<sqlite3.Database>? _ffiDBFuture;
static Future<sqlite_async.SqliteDatabase>? _sqliteAsyncDBFuture;
+ @Deprecated("Use ffiDB instead (sqlite_async)")
Future<Database> get database async {
// lazily instantiate the db the first time it is accessed
_dbFuture ??= _initDatabase();
@@ -478,8 +479,8 @@ class FilesDB {
}
Future<EnteFile?> getFile(int generatedID) async {
- final db = await instance.ffiDB;
- final results = db.select(
+ final db = await instance.sqliteAsyncDB;
+ final results = await db.getAll(
'SELECT * FROM $filesTable WHERE $columnGeneratedID = ?',
[generatedID],
);
@@ -490,8 +491,8 @@ class FilesDB {
}
Future<EnteFile?> getUploadedFile(int uploadedID, int collectionID) async {
- final db = await instance.ffiDB;
- final results = db.select(
+ final db = await instance.sqliteAsyncDB;
+ final results = await db.getAll(
'SELECT * FROM $filesTable WHERE $columnUploadedFileID = ? AND $columnCollectionID = ?',
[
uploadedID,
@@ -505,8 +506,8 @@ class FilesDB {
}
Future<Set<int>> getUploadedFileIDs(int collectionID) async {
- final db = await instance.ffiDB;
- final results = db.select(
+ final db = await instance.sqliteAsyncDB;
+ final results = await db.getAll(
'SELECT $columnUploadedFileID FROM $filesTable'
' WHERE $columnCollectionID = ? AND ($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1)',
[
@@ -756,41 +757,6 @@ class FilesDB {
final results = await db.getAll(
query,
);
-
- final files = convertToFiles(results);
- return applyDBFilters(
- files,
- DBFilterOptions(ignoredCollectionIDs: ignoredCollectionIDs),
- );
- }
-
- Future<List<EnteFile>> getFilesCreatedWithinDurationsSync(
- List<List<int>> durations,
- Set<int> ignoredCollectionIDs, {
- int? visibility,
- String order = 'ASC',
- }) async {
- if (durations.isEmpty) {
- return <EnteFile>[];
- }
- final db = await instance.ffiDB;
- String whereClause = "( ";
- for (int index = 0; index < durations.length; index++) {
- whereClause += "($columnCreationTime >= " +
- durations[index][0].toString() +
- " AND $columnCreationTime < " +
- durations[index][1].toString() +
- ")";
- if (index != durations.length - 1) {
- whereClause += " OR ";
- } else if (visibility != null) {
- whereClause += ' AND $columnMMdVisibility = $visibility';
- }
- }
- whereClause += ")";
- final results = db.select(
- 'select * from $filesTable where $whereClause order by $columnCreationTime $order',
- );
final files = convertToFiles(results);
return applyDBFilters(
files,
diff --git a/mobile/lib/services/memories_service.dart b/mobile/lib/services/memories_service.dart
index de68e2dabc..6461131289 100644
--- a/mobile/lib/services/memories_service.dart
+++ b/mobile/lib/services/memories_service.dart
@@ -107,7 +107,7 @@ class MemoriesService extends ChangeNotifier {
}
final ignoredCollections =
CollectionsService.instance.archivedOrHiddenCollectionIds();
- final files = await _filesDB.getFilesCreatedWithinDurationsSync(
+ final files = await _filesDB.getFilesCreatedWithinDurations(
durations,
ignoredCollections,
visibility: visibleVisibility,
diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock
index 393dadc237..d40f8b0c4c 100644
--- a/mobile/pubspec.lock
+++ b/mobile/pubspec.lock
@@ -2039,7 +2039,7 @@ packages:
source: hosted
version: "0.3.0"
sqlite3:
- dependency: "direct main"
+ dependency: transitive
description:
name: sqlite3
sha256: "072128763f1547e3e9b4735ce846bfd226d68019ccda54db4cd427b12dfdedc9"
diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml
index 89bee933b1..9f6e7065c4 100644
--- a/mobile/pubspec.yaml
+++ b/mobile/pubspec.yaml
@@ -140,7 +140,6 @@ dependencies:
shared_preferences: ^2.0.5
sqflite: ^2.3.0
sqflite_migration: ^0.3.0
- sqlite3: ^2.1.0
sqlite3_flutter_libs: ^0.5.20
sqlite_async: ^0.6.1
step_progress_indicator: ^1.0.2