remove old retransmission messages

This commit is contained in:
otsmr 2025-07-17 19:44:18 +02:00
parent c70413cf6a
commit c4b928f1b9
3 changed files with 16 additions and 4 deletions

View file

@ -46,7 +46,8 @@ void main() async {
twonlyDB = TwonlyDatabase();
await twonlyDB.messagesDao.resetPendingDownloadState();
await twonlyDB.messagesDao.handleMediaFilesOlderThan7Days();
await twonlyDB.messagesDao.handleMediaFilesOlderThan30Days();
await twonlyDB.messageRetransmissionDao.purgeOldRetransmissions();
await twonlyDB.signalDao.purgeOutDatedPreKeys();
// Purge media files in the background

View file

@ -22,6 +22,17 @@ class MessageRetransmissionDao extends DatabaseAccessor<TwonlyDatabase>
}
}
Future<void> purgeOldRetransmissions() async {
// delete entries older than two weeks
await (delete(messageRetransmissions)
..where((t) => (t.acknowledgeByServerAt.isSmallerThanValue(
DateTime.now().subtract(
const Duration(days: 25),
),
))))
.go();
}
Future<List<int>> getRetransmitAbleMessages() async {
final countDeleted = await (delete(messageRetransmissions)
..where((t) =>

View file

@ -69,8 +69,8 @@ class MessagesDao extends DatabaseAccessor<TwonlyDatabase>
.write(const MessagesCompanion(contentJson: Value(null)));
}
Future<void> handleMediaFilesOlderThan7Days() {
/// media files will be deleted by the server after 7 days, so delete them here also
Future<void> handleMediaFilesOlderThan30Days() {
/// media files will be deleted by the server after 30 days, so delete them here also
return (update(messages)
..where(
(t) => (t.kind.equals(MessageKind.media.name) &
@ -78,7 +78,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDatabase>
t.messageOtherId.isNull() &
(t.sendAt.isSmallerThanValue(
DateTime.now().subtract(
const Duration(days: 8),
const Duration(days: 30),
),
))),
))