Skip to content

armgit / ente

Public Imported from GitHub
0

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

Migrate getAllPendingOrUploadedFiles from sqflite to sqlite_async

ashilkn1ec941b0224d
diff --git a/mobile/lib/db/files_db.dart b/mobile/lib/db/files_db.dart
index 5ffd710e5e..dd941a9798 100644
--- a/mobile/lib/db/files_db.dart
+++ b/mobile/lib/db/files_db.dart
@@ -573,31 +573,43 @@ class FilesDB {
bool applyOwnerCheck = false,
}) async {
final stopWatch = EnteWatch('getAllPendingOrUploadedFiles')..start();
- late String whereQuery;
- late List<Object?>? whereArgs;
+ final order = (asc ?? false ? 'ASC' : 'DESC');
+
+ late String query;
+ late List<Object?>? args;
if (applyOwnerCheck) {
- whereQuery = '$columnCreationTime >= ? AND $columnCreationTime <= ? '
+ query =
+ 'SELECT * FROM $filesTable WHERE $columnCreationTime >= ? AND $columnCreationTime <= ? '
'AND ($columnOwnerID IS NULL OR $columnOwnerID = ?) '
'AND ($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1)'
- ' AND $columnMMdVisibility = ?';
- whereArgs = [startTime, endTime, ownerID, visibility];
+ ' AND $columnMMdVisibility = ? ORDER BY $columnCreationTime $order, $columnModificationTime $order';
+
+ args = [startTime, endTime, ownerID, visibility];
} else {
- whereQuery =
- '$columnCreationTime >= ? AND $columnCreationTime <= ? AND ($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1)'
- ' AND $columnMMdVisibility = ?';
- whereArgs = [startTime, endTime, visibility];
+ query =
+ 'SELECT * FROM $filesTable WHERE $columnCreationTime >= ? AND $columnCreationTime <= ? '
+ 'AND ($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1)'
+ ' AND $columnMMdVisibility = ? ORDER BY $columnCreationTime $order, $columnModificationTime $order';
+ args = [startTime, endTime, visibility];
}
- final db = await instance.database;
- final order = (asc ?? false ? 'ASC' : 'DESC');
- final results = await db.query(
- filesTable,
- where: whereQuery,
- whereArgs: whereArgs,
- orderBy:
- '$columnCreationTime ' + order + ', $columnModificationTime ' + order,
- limit: limit,
+ if (limit != null) {
+ query += ' LIMIT ?';
+ args.add(limit);
+ }
+
+ _logger.info(
+ "--------------------------- getAllPendingOrUploadedFilesSqliteAsync with limit: $limit",
);
+ final stopwatch = Stopwatch()..start();
+
+ final db = await instance.sqliteAsyncDB;
+ final results = await db.getAll(query, args);
+ _logger.info(
+ "------------------------getAllPendingOrUploadedFilesSqliteAsync query took ${stopwatch.elapsedMilliseconds} ms",
+ );
+ stopwatch.stop();
+ _logger.info("message");
stopWatch.log('queryDone');
final files = convertToFiles(results);
stopWatch.log('convertDone');
@@ -1600,8 +1612,9 @@ class FilesDB {
Set<int> collectionsToIgnore, {
bool dedupeByUploadId = true,
}) async {
+ final stopwatch = Stopwatch()..start();
+ _logger.info("-------------------- getAllFilesFromDB");
final db = await instance.sqliteAsyncDB;
-
final result = await db.getAll(
'SELECT * FROM $filesTable ORDER BY $columnCreationTime DESC',
);
@@ -1615,6 +1628,10 @@ class FilesDB {
dedupeUploadID: dedupeByUploadId,
),
);
+ _logger.info(
+ "---------------------------- getAllFilesFromDB took ${stopwatch.elapsedMilliseconds} ms",
+ );
+ stopwatch.stop();
return deduplicatedFiles;
}