|
@@ -573,31 +573,34 @@ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ final db = await instance.sqliteAsyncDB;
|
|
|
+ final results = await db.getAll(query, args);
|
|
|
+ _logger.info("message");
|
|
|
stopWatch.log('queryDone');
|
|
|
final files = convertToFiles(results);
|
|
|
stopWatch.log('convertDone');
|
|
@@ -609,23 +612,25 @@ class FilesDB {
|
|
|
|
|
|
Future<FileLoadResult> getAllLocalAndUploadedFiles(
|
|
|
int startTime,
|
|
|
- int endTime,
|
|
|
- int ownerID, {
|
|
|
+ int endTime, {
|
|
|
int? limit,
|
|
|
bool? asc,
|
|
|
required DBFilterOptions filterOptions,
|
|
|
}) async {
|
|
|
- final db = await instance.database;
|
|
|
+ final db = await instance.sqliteAsyncDB;
|
|
|
final order = (asc ?? false ? 'ASC' : 'DESC');
|
|
|
- final results = await db.query(
|
|
|
- filesTable,
|
|
|
- where:
|
|
|
- '$columnCreationTime >= ? AND $columnCreationTime <= ? AND ($columnMMdVisibility IS NULL OR $columnMMdVisibility = ?)'
|
|
|
- ' AND ($columnLocalID IS NOT NULL OR ($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1))',
|
|
|
- whereArgs: [startTime, endTime, visibleVisibility],
|
|
|
- orderBy:
|
|
|
- '$columnCreationTime ' + order + ', $columnModificationTime ' + order,
|
|
|
- limit: limit,
|
|
|
+ final args = [startTime, endTime, visibleVisibility];
|
|
|
+ String query =
|
|
|
+ 'SELECT * FROM $filesTable WHERE $columnCreationTime >= ? AND $columnCreationTime <= ? AND ($columnMMdVisibility IS NULL OR $columnMMdVisibility = ?)'
|
|
|
+ ' AND ($columnLocalID IS NOT NULL OR ($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1))'
|
|
|
+ ' ORDER BY $columnCreationTime $order, $columnModificationTime $order';
|
|
|
+ if (limit != null) {
|
|
|
+ query += ' LIMIT ?';
|
|
|
+ args.add(limit);
|
|
|
+ }
|
|
|
+ final results = await db.getAll(
|
|
|
+ query,
|
|
|
+ args,
|
|
|
);
|
|
|
final files = convertToFiles(results);
|
|
|
final List<EnteFile> filteredFiles =
|
|
@@ -658,19 +663,18 @@ class FilesDB {
|
|
|
bool? asc,
|
|
|
int visibility = visibleVisibility,
|
|
|
}) async {
|
|
|
- final db = await instance.database;
|
|
|
+ final db = await instance.sqliteAsyncDB;
|
|
|
final order = (asc ?? false ? 'ASC' : 'DESC');
|
|
|
- const String whereClause =
|
|
|
- '$columnCollectionID = ? AND $columnCreationTime >= ? AND $columnCreationTime <= ?';
|
|
|
- final List<Object> whereArgs = [collectionID, startTime, endTime];
|
|
|
-
|
|
|
- final results = await db.query(
|
|
|
- filesTable,
|
|
|
- where: whereClause,
|
|
|
- whereArgs: whereArgs,
|
|
|
- orderBy:
|
|
|
- '$columnCreationTime ' + order + ', $columnModificationTime ' + order,
|
|
|
- limit: limit,
|
|
|
+ String query =
|
|
|
+ 'SELECT * FROM $filesTable WHERE $columnCollectionID = ? AND $columnCreationTime >= ? AND $columnCreationTime <= ? ORDER BY $columnCreationTime $order, $columnModificationTime $order';
|
|
|
+ final List<Object> args = [collectionID, startTime, endTime];
|
|
|
+ if (limit != null) {
|
|
|
+ query += ' LIMIT ?';
|
|
|
+ args.add(limit);
|
|
|
+ }
|
|
|
+ final results = await db.getAll(
|
|
|
+ query,
|
|
|
+ args,
|
|
|
);
|
|
|
final files = convertToFiles(results);
|
|
|
return FileLoadResult(files, files.length == limit);
|
|
@@ -1601,7 +1605,6 @@ class FilesDB {
|
|
|
bool dedupeByUploadId = true,
|
|
|
}) async {
|
|
|
final db = await instance.sqliteAsyncDB;
|
|
|
-
|
|
|
final result = await db.getAll(
|
|
|
'SELECT * FROM $filesTable ORDER BY $columnCreationTime DESC',
|
|
|
);
|