chore: remove formatting for files_db
This commit is contained in:
@@ -74,9 +74,9 @@ class FilesDB with SqlDbBase {
|
||||
// we need to write query based on that field
|
||||
static const columnMMdVisibility = 'mmd_visibility';
|
||||
|
||||
//If adding or removing a new column, make sure to update the `_columnNames` list
|
||||
//and update `_generateColumnsAndPlaceholdersForInsert` and
|
||||
//`_generateUpdateAssignmentsWithPlaceholders`
|
||||
//If adding or removing a new column, make sure to update the `_columnNames` list
|
||||
//and update `_generateColumnsAndPlaceholdersForInsert` and
|
||||
//`_generateUpdateAssignmentsWithPlaceholders`
|
||||
static final _migrationScripts = [
|
||||
...createTable(filesTable),
|
||||
...alterDeviceFolderToAllowNULL(),
|
||||
@@ -194,7 +194,7 @@ class FilesDB with SqlDbBase {
|
||||
''',
|
||||
'''
|
||||
CREATE INDEX IF NOT EXISTS updation_time_index ON $filesTable($columnUpdationTime);
|
||||
''',
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ class FilesDB with SqlDbBase {
|
||||
|
||||
ALTER TABLE $tempTable
|
||||
RENAME TO $filesTable;
|
||||
''',
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ class FilesDB with SqlDbBase {
|
||||
''',
|
||||
'''
|
||||
ALTER TABLE $filesTable ADD COLUMN $columnMMdVisibility INTEGER DEFAULT $visibleVisibility;
|
||||
''',
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ class FilesDB with SqlDbBase {
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS cid_uid ON $filesTable ($columnCollectionID, $columnUploadedFileID)
|
||||
WHERE $columnCollectionID is not NULL AND $columnUploadedFileID is not NULL
|
||||
AND $columnCollectionID != -1 AND $columnUploadedFileID != -1;
|
||||
''',
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ class FilesDB with SqlDbBase {
|
||||
''',
|
||||
'''
|
||||
ALTER TABLE $filesTable ADD COLUMN $columnPubMMdVersion INTEGER DEFAULT 0;
|
||||
''',
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ class FilesDB with SqlDbBase {
|
||||
data TEXT NOT NULL DEFAULT '{}',
|
||||
updatedAt INTEGER NOT NULL
|
||||
);
|
||||
''',
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ class FilesDB with SqlDbBase {
|
||||
''',
|
||||
'''
|
||||
CREATE INDEX IF NOT EXISTS added_time_index ON $filesTable($columnAddedTime);
|
||||
''',
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
@@ -507,9 +507,8 @@ class FilesDB with SqlDbBase {
|
||||
Future<void> insert(EnteFile file) async {
|
||||
_logger.info("Inserting $file");
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final columnsAndPlaceholders = _generateColumnsAndPlaceholdersForInsert(
|
||||
fileGenId: file.generatedID,
|
||||
);
|
||||
final columnsAndPlaceholders =
|
||||
_generateColumnsAndPlaceholdersForInsert(fileGenId: file.generatedID);
|
||||
final values = _getParameterSetForFile(file);
|
||||
|
||||
await db.execute(
|
||||
@@ -521,9 +520,8 @@ class FilesDB with SqlDbBase {
|
||||
Future<int> insertAndGetId(EnteFile file) async {
|
||||
_logger.info("Inserting $file");
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final columnsAndPlaceholders = _generateColumnsAndPlaceholdersForInsert(
|
||||
fileGenId: file.generatedID,
|
||||
);
|
||||
final columnsAndPlaceholders =
|
||||
_generateColumnsAndPlaceholdersForInsert(fileGenId: file.generatedID);
|
||||
final values = _getParameterSetForFile(file);
|
||||
return await db.writeTransaction((tx) async {
|
||||
await tx.execute(
|
||||
@@ -551,7 +549,10 @@ class FilesDB with SqlDbBase {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final results = await db.getAll(
|
||||
'SELECT * FROM $filesTable WHERE $columnUploadedFileID = ? AND $columnCollectionID = ?',
|
||||
[uploadedID, collectionID],
|
||||
[
|
||||
uploadedID,
|
||||
collectionID,
|
||||
],
|
||||
);
|
||||
if (results.isEmpty) {
|
||||
return null;
|
||||
@@ -576,7 +577,9 @@ class FilesDB with SqlDbBase {
|
||||
final results = await db.getAll(
|
||||
'SELECT $columnUploadedFileID FROM $filesTable'
|
||||
' WHERE $columnCollectionID = ? AND ($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1)',
|
||||
[collectionID],
|
||||
[
|
||||
collectionID,
|
||||
],
|
||||
);
|
||||
final ids = <int>{};
|
||||
for (final result in results) {
|
||||
@@ -592,7 +595,9 @@ class FilesDB with SqlDbBase {
|
||||
final results = await db.getAll(
|
||||
'SELECT $columnUploadedFileID, $columnHash FROM $filesTable'
|
||||
' WHERE $columnCollectionID = ? AND ($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1)',
|
||||
[collectionID],
|
||||
[
|
||||
collectionID,
|
||||
],
|
||||
);
|
||||
final ids = <int>{};
|
||||
final hash = <String, int>{};
|
||||
@@ -644,16 +649,14 @@ class FilesDB with SqlDbBase {
|
||||
late List<Object?>? args;
|
||||
if (applyOwnerCheck) {
|
||||
subQueries.add(
|
||||
'SELECT * FROM $filesTable WHERE $columnCreationTime >= ? AND $columnCreationTime <= ? '
|
||||
'AND ($columnOwnerID IS NULL OR $columnOwnerID = ?) '
|
||||
'AND ($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1)',
|
||||
);
|
||||
'SELECT * FROM $filesTable WHERE $columnCreationTime >= ? AND $columnCreationTime <= ? '
|
||||
'AND ($columnOwnerID IS NULL OR $columnOwnerID = ?) '
|
||||
'AND ($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1)');
|
||||
args = [startTime, endTime, ownerID];
|
||||
} else {
|
||||
subQueries.add(
|
||||
'SELECT * FROM $filesTable WHERE $columnCreationTime >= ? AND $columnCreationTime <= ? '
|
||||
'AND ($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1)',
|
||||
);
|
||||
'SELECT * FROM $filesTable WHERE $columnCreationTime >= ? AND $columnCreationTime <= ? '
|
||||
'AND ($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1)');
|
||||
args = [startTime, endTime];
|
||||
}
|
||||
|
||||
@@ -701,9 +704,8 @@ class FilesDB with SqlDbBase {
|
||||
final subQueries = <String>[];
|
||||
|
||||
subQueries.add(
|
||||
'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))',
|
||||
);
|
||||
'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))');
|
||||
|
||||
if (filterOptions.ignoreSharedItems) {
|
||||
subQueries.add(' AND $columnOwnerID = ?');
|
||||
@@ -721,12 +723,13 @@ class FilesDB with SqlDbBase {
|
||||
|
||||
final finalQuery = subQueries.join();
|
||||
|
||||
final results = await db.getAll(finalQuery, args);
|
||||
final files = convertToFiles(results);
|
||||
final List<EnteFile> filteredFiles = await applyDBFilters(
|
||||
files,
|
||||
filterOptions,
|
||||
final results = await db.getAll(
|
||||
finalQuery,
|
||||
args,
|
||||
);
|
||||
final files = convertToFiles(results);
|
||||
final List<EnteFile> filteredFiles =
|
||||
await applyDBFilters(files, filterOptions);
|
||||
return FileLoadResult(filteredFiles, files.length == limit);
|
||||
}
|
||||
|
||||
@@ -764,7 +767,10 @@ class FilesDB with SqlDbBase {
|
||||
query += ' LIMIT ?';
|
||||
args.add(limit);
|
||||
}
|
||||
final results = await db.getAll(query, args);
|
||||
final results = await db.getAll(
|
||||
query,
|
||||
args,
|
||||
);
|
||||
final files = convertToFiles(results);
|
||||
return FileLoadResult(files, files.length == limit);
|
||||
}
|
||||
@@ -834,12 +840,13 @@ class FilesDB with SqlDbBase {
|
||||
query += ' LIMIT ?';
|
||||
whereArgs.add(limit);
|
||||
}
|
||||
final results = await db.getAll(query, whereArgs);
|
||||
final files = convertToFiles(results);
|
||||
final dedupeResult = await applyDBFilters(
|
||||
files,
|
||||
DBFilterOptions.dedupeOption,
|
||||
final results = await db.getAll(
|
||||
query,
|
||||
whereArgs,
|
||||
);
|
||||
final files = convertToFiles(results);
|
||||
final dedupeResult =
|
||||
await applyDBFilters(files, DBFilterOptions.dedupeOption);
|
||||
_logger.info("Fetched " + dedupeResult.length.toString() + " files");
|
||||
return FileLoadResult(files, files.length == limit);
|
||||
}
|
||||
@@ -867,7 +874,9 @@ class FilesDB with SqlDbBase {
|
||||
}
|
||||
final query =
|
||||
'SELECT * FROM $filesTable WHERE $whereClause ORDER BY $columnCreationTime $order';
|
||||
final results = await db.getAll(query);
|
||||
final results = await db.getAll(
|
||||
query,
|
||||
);
|
||||
final files = convertToFiles(results);
|
||||
return applyDBFilters(
|
||||
files,
|
||||
@@ -1055,12 +1064,14 @@ class FilesDB with SqlDbBase {
|
||||
) async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final inParam = localIDs.map((id) => "'$id'").join(',');
|
||||
await db.execute('''
|
||||
await db.execute(
|
||||
'''
|
||||
UPDATE $filesTable
|
||||
SET $columnCollectionID = $collectionID
|
||||
WHERE $columnLocalID IN ($inParam) AND ($columnCollectionID IS NULL OR
|
||||
$columnCollectionID = -1);
|
||||
''');
|
||||
''',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> markFilesForReUpload(
|
||||
@@ -1116,15 +1127,29 @@ class FilesDB with SqlDbBase {
|
||||
String query = '''SELECT * FROM $filesTable WHERE ($columnOwnerID = ?
|
||||
OR $columnOwnerID IS NULL) AND $columnLocalID = ?
|
||||
AND $columnFileType = ? AND ($columnTitle=? OR $columnTitle IS NULL) ''';
|
||||
List<Object> whereArgs = [ownerID, localID, getInt(fileType), title];
|
||||
List<Object> whereArgs = [
|
||||
ownerID,
|
||||
localID,
|
||||
getInt(fileType),
|
||||
title,
|
||||
];
|
||||
if (Platform.isAndroid) {
|
||||
query = '''SELECT * FROM $filesTable WHERE ($columnOwnerID = ? OR
|
||||
$columnOwnerID IS NULL) AND $columnLocalID = ? AND $columnFileType = ?
|
||||
AND $columnTitle=? AND $columnDeviceFolder= ? ''';
|
||||
whereArgs = [ownerID, localID, getInt(fileType), title, deviceFolder];
|
||||
whereArgs = [
|
||||
ownerID,
|
||||
localID,
|
||||
getInt(fileType),
|
||||
title,
|
||||
deviceFolder,
|
||||
];
|
||||
}
|
||||
|
||||
final rows = await db.getAll(query, whereArgs);
|
||||
final rows = await db.getAll(
|
||||
query,
|
||||
whereArgs,
|
||||
);
|
||||
|
||||
return convertToFiles(rows);
|
||||
}
|
||||
@@ -1166,7 +1191,10 @@ class FilesDB with SqlDbBase {
|
||||
'SELECT * FROM $filesTable WHERE ($columnUploadedFileID != NULL OR '
|
||||
'$columnUploadedFileID != -1) AND $columnOwnerID = ? AND '
|
||||
'$columnFileType = ? AND $columnHash IN ($inParam)',
|
||||
[ownerID, getInt(fileType)],
|
||||
[
|
||||
ownerID,
|
||||
getInt(fileType),
|
||||
],
|
||||
);
|
||||
return convertToFiles(rows);
|
||||
}
|
||||
@@ -1211,9 +1239,10 @@ class FilesDB with SqlDbBase {
|
||||
Future<void> deleteByGeneratedID(int genID) async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
|
||||
await db.execute('DELETE FROM $filesTable WHERE $columnGeneratedID = ?', [
|
||||
genID,
|
||||
]);
|
||||
await db.execute(
|
||||
'DELETE FROM $filesTable WHERE $columnGeneratedID = ?',
|
||||
[genID],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteMultipleUploadedFiles(List<int> uploadedFileIDs) async {
|
||||
@@ -1261,11 +1290,13 @@ class FilesDB with SqlDbBase {
|
||||
Future<void> deleteLocalFiles(List<String> localIDs) async {
|
||||
final inParam = localIDs.map((id) => "'$id'").join(',');
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
await db.execute('''
|
||||
await db.execute(
|
||||
'''
|
||||
UPDATE $filesTable
|
||||
SET $columnLocalID = NULL
|
||||
WHERE $columnLocalID IN ($inParam);
|
||||
''');
|
||||
''',
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<EnteFile>> getLocalFiles(
|
||||
@@ -1295,10 +1326,12 @@ class FilesDB with SqlDbBase {
|
||||
final inParam = localIDs.map((id) => "'$id'").join(',');
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
unawaited(
|
||||
db.execute('''
|
||||
db.execute(
|
||||
'''
|
||||
DELETE FROM $filesTable
|
||||
WHERE ($columnUploadedFileID is NULL OR $columnUploadedFileID = -1 ) AND $columnLocalID IN ($inParam)
|
||||
'''),
|
||||
''',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1346,9 +1379,10 @@ class FilesDB with SqlDbBase {
|
||||
Future<void> deleteCollection(int collectionID) async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
unawaited(
|
||||
db.execute('DELETE FROM $filesTable WHERE $columnCollectionID = ?', [
|
||||
collectionID,
|
||||
]),
|
||||
db.execute(
|
||||
'DELETE FROM $filesTable WHERE $columnCollectionID = ?',
|
||||
[collectionID],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1385,12 +1419,14 @@ class FilesDB with SqlDbBase {
|
||||
.map((file) => "'${file.localID}'")
|
||||
.join(',');
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final rows = await db.getAll('''
|
||||
final rows = await db.getAll(
|
||||
'''
|
||||
SELECT $columnLocalID
|
||||
FROM $filesTable
|
||||
WHERE $columnLocalID IN ($inParam) AND $columnCollectionID !=
|
||||
$collectionID AND $columnLocalID IS NOT NULL;
|
||||
''');
|
||||
''',
|
||||
);
|
||||
final result = <String>{};
|
||||
for (final row in rows) {
|
||||
result.add(row[columnLocalID] as String);
|
||||
@@ -1403,7 +1439,8 @@ class FilesDB with SqlDbBase {
|
||||
Future<Map<int, int>> getCollectionIDToMaxCreationTime() async {
|
||||
final enteWatch = EnteWatch("getCollectionIDToMaxCreationTime")..start();
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final rows = await db.getAll('''
|
||||
final rows = await db.getAll(
|
||||
'''
|
||||
SELECT $columnCollectionID, MAX($columnCreationTime) AS max_creation_time
|
||||
FROM $filesTable
|
||||
WHERE
|
||||
@@ -1411,7 +1448,8 @@ class FilesDB with SqlDbBase {
|
||||
AND $columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS
|
||||
NOT -1)
|
||||
GROUP BY $columnCollectionID;
|
||||
''');
|
||||
''',
|
||||
);
|
||||
final result = <int, int>{};
|
||||
for (final row in rows) {
|
||||
result[row[columnCollectionID] as int] = row['max_creation_time'] as int;
|
||||
@@ -1422,12 +1460,14 @@ class FilesDB with SqlDbBase {
|
||||
|
||||
Future<Map<int, int>> getFileIDToCreationTime() async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final rows = await db.getAll('''
|
||||
final rows = await db.getAll(
|
||||
'''
|
||||
SELECT $columnUploadedFileID, $columnCreationTime
|
||||
FROM $filesTable
|
||||
WHERE
|
||||
($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1);
|
||||
''');
|
||||
''',
|
||||
);
|
||||
final result = <int, int>{};
|
||||
for (final row in rows) {
|
||||
result[row[columnUploadedFileID] as int] = row[columnCreationTime] as int;
|
||||
@@ -1539,7 +1579,9 @@ class FilesDB with SqlDbBase {
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Set<int>> getAllCollectionIDsOfFile(int uploadedFileID) async {
|
||||
Future<Set<int>> getAllCollectionIDsOfFile(
|
||||
int uploadedFileID,
|
||||
) async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final results = await db.getAll(
|
||||
'''
|
||||
@@ -1562,10 +1604,12 @@ class FilesDB with SqlDbBase {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final inParam = uploadedFileIDs.join(',');
|
||||
|
||||
final results = await db.getAll('''
|
||||
final results = await db.getAll(
|
||||
'''
|
||||
SELECT $columnCollectionID FROM $filesTable
|
||||
WHERE $columnUploadedFileID IN ($inParam) AND $columnCollectionID != -1
|
||||
''');
|
||||
''',
|
||||
);
|
||||
final collectionIDsOfFiles = <int>[];
|
||||
for (var result in results) {
|
||||
collectionIDsOfFiles.add(result['collection_id'] as int);
|
||||
@@ -1618,7 +1662,10 @@ class FilesDB with SqlDbBase {
|
||||
final parameterSets = <List<Object?>>[];
|
||||
|
||||
for (final uploadedFileID in uploadedFileIDToSize.keys) {
|
||||
parameterSets.add([uploadedFileIDToSize[uploadedFileID], uploadedFileID]);
|
||||
parameterSets.add([
|
||||
uploadedFileIDToSize[uploadedFileID],
|
||||
uploadedFileID,
|
||||
]);
|
||||
}
|
||||
|
||||
await db.executeBatch(
|
||||
@@ -1664,10 +1711,8 @@ class FilesDB with SqlDbBase {
|
||||
);
|
||||
_logger.info("${result.length} rows in filesDB");
|
||||
|
||||
final List<EnteFile> files = await Computer.shared().compute(
|
||||
convertToFilesForIsolate,
|
||||
param: {"result": result},
|
||||
);
|
||||
final List<EnteFile> files = await Computer.shared()
|
||||
.compute(convertToFilesForIsolate, param: {"result": result});
|
||||
|
||||
final List<EnteFile> deduplicatedFiles = await applyDBFilters(
|
||||
files,
|
||||
@@ -1705,12 +1750,13 @@ class FilesDB with SqlDbBase {
|
||||
args.add(limit);
|
||||
}
|
||||
|
||||
final results = await db.getAll(query, args);
|
||||
final files = convertToFiles(results);
|
||||
final List<EnteFile> filteredFiles = await applyDBFilters(
|
||||
files,
|
||||
filterOptions,
|
||||
final results = await db.getAll(
|
||||
query,
|
||||
args,
|
||||
);
|
||||
final files = convertToFiles(results);
|
||||
final List<EnteFile> filteredFiles =
|
||||
await applyDBFilters(files, filterOptions);
|
||||
return FileLoadResult(filteredFiles, files.length == limit);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user