fix open group trimming & removing unread disappearing messages after 14 days

pull/941/head
ryanzhao 2 years ago
parent 491ca58e9d
commit 8caed9dc9c

@ -16,6 +16,7 @@ public enum GarbageCollectionJob: JobExecutor {
public static var requiresThreadId: Bool = false public static var requiresThreadId: Bool = false
public static let requiresInteractionId: Bool = false public static let requiresInteractionId: Bool = false
public static let approxSixMonthsInSeconds: TimeInterval = (6 * 30 * 24 * 60 * 60) 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 private static let minInteractionsToTrim: Int = 2000
public static func run( public static func run(
@ -96,7 +97,7 @@ public enum GarbageCollectionJob: JobExecutor {
GROUP BY \(interaction[.threadId]) GROUP BY \(interaction[.threadId])
) AS interactionInfo ON interactionInfo.\(threadIdLiteral) = \(interaction[.threadId]) ) AS interactionInfo ON interactionInfo.\(threadIdLiteral) = \(interaction[.threadId])
WHERE ( WHERE (
\(interaction[.timestampMs]) < \(timestampNow - approxSixMonthsInSeconds) AND \(interaction[.timestampMs]) < \((timestampNow - approxSixMonthsInSeconds) * 1000) AND
interactionInfo.interactionCount >= \(minInteractionsToTrimSql) 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 completion: { _, _ in
// Dispatch async so we can swap from the write queue to a read one (we are done writing) // 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 orphanedAttachments
case orphanedAttachmentFiles case orphanedAttachmentFiles
case orphanedProfileAvatars case orphanedProfileAvatars
case expiredUnreadDisappearingMessages // unread disappearing messages after 14 days
} }
public struct Details: Codable { public struct Details: Codable {

Loading…
Cancel
Save