From 8caed9dc9c1514c3474fcc2e1b0ded4fce640f57 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 6 Dec 2022 14:25:03 +1100 Subject: [PATCH] fix open group trimming & removing unread disappearing messages after 14 days --- .../Jobs/Types/GarbageCollectionJob.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SessionMessagingKit/Jobs/Types/GarbageCollectionJob.swift b/SessionMessagingKit/Jobs/Types/GarbageCollectionJob.swift index 6c47e876f..43acdd742 100644 --- a/SessionMessagingKit/Jobs/Types/GarbageCollectionJob.swift +++ b/SessionMessagingKit/Jobs/Types/GarbageCollectionJob.swift @@ -16,6 +16,7 @@ public enum GarbageCollectionJob: JobExecutor { public static var requiresThreadId: Bool = false public static let requiresInteractionId: Bool = false public static let approxSixMonthsInSeconds: TimeInterval = (6 * 30 * 24 * 60 * 60) + public static let fourteenDaysInSeconds: TimeInterval = (14 * 24 * 60 * 60) private static let minInteractionsToTrim: Int = 2000 public static func run( @@ -96,7 +97,7 @@ public enum GarbageCollectionJob: JobExecutor { GROUP BY \(interaction[.threadId]) ) AS interactionInfo ON interactionInfo.\(threadIdLiteral) = \(interaction[.threadId]) WHERE ( - \(interaction[.timestampMs]) < \(timestampNow - approxSixMonthsInSeconds) AND + \(interaction[.timestampMs]) < \((timestampNow - approxSixMonthsInSeconds) * 1000) AND interactionInfo.interactionCount >= \(minInteractionsToTrimSql) ) ) @@ -289,6 +290,15 @@ public enum GarbageCollectionJob: JobExecutor { ) """) } + + /// Remove interactions which should be disappearing after read but never be read within 14 days + if finalTypesToCollection.contains(.expiredUnreadDisappearingMessages) { + _ = try Interaction + .filter(Interaction.Columns.expiresInSeconds != nil) + .filter(Interaction.Columns.expiresStartedAtMs == nil) + .filter(Interaction.Columns.timestampMs < (timestampNow - fourteenDaysInSeconds) * 1000) + .deleteAll(db) + } }, completion: { _, _ in // Dispatch async so we can swap from the write queue to a read one (we are done writing) @@ -442,6 +452,7 @@ extension GarbageCollectionJob { case orphanedAttachments case orphanedAttachmentFiles case orphanedProfileAvatars + case expiredUnreadDisappearingMessages // unread disappearing messages after 14 days } public struct Details: Codable {