fix: Delete files older than 30 days

This commit is contained in:
Sorunome 2020-10-06 11:48:34 +02:00 committed by Christian Pauly
parent 0761d33b6f
commit 2e941b85e9
3 changed files with 12 additions and 0 deletions

View file

@ -749,6 +749,8 @@ class Client extends MatrixApi {
_sortRooms(); _sortRooms();
} }
prevBatch = syncResp.nextBatch; prevBatch = syncResp.nextBatch;
await database?.deleteOldFiles(
DateTime.now().subtract(Duration(days: 30)).millisecondsSinceEpoch);
await _updateUserDeviceKeys(); await _updateUserDeviceKeys();
if (encryptionEnabled) { if (encryptionEnabled) {
encryption.onSync(); encryption.onSync();

View file

@ -6892,6 +6892,15 @@ abstract class _$Database extends GeneratedDatabase {
); );
} }
Future<int> deleteOldFiles(int saved_at) {
return customUpdate(
'DELETE FROM files WHERE saved_at < :saved_at',
variables: [Variable.withInt(saved_at)],
updates: {files},
updateKind: UpdateKind.delete,
);
}
@override @override
Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>(); Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>();
@override @override

View file

@ -234,3 +234,4 @@ removeSuccessfulRoomEvents: DELETE FROM events WHERE client_id = :client_id AND
storeFile: INSERT OR REPLACE INTO files (mxc_uri, bytes, saved_at) VALUES (:mxc_uri, :bytes, :time); storeFile: INSERT OR REPLACE INTO files (mxc_uri, bytes, saved_at) VALUES (:mxc_uri, :bytes, :time);
dbGetFile: SELECT * FROM files WHERE mxc_uri = :mxc_uri; dbGetFile: SELECT * FROM files WHERE mxc_uri = :mxc_uri;
markPendingEventsAsError: UPDATE events SET status = -1 WHERE client_id = :client_id AND status = 0; markPendingEventsAsError: UPDATE events SET status = -1 WHERE client_id = :client_id AND status = 0;
deleteOldFiles: DELETE FROM files WHERE saved_at < :saved_at;