From c01cbfdeef02f140ec0d04a87c0cf6a1ba685eb4 Mon Sep 17 00:00:00 2001 From: Harry <109690906+harry-signal@users.noreply.github.com> Date: Fri, 29 Aug 2025 11:58:19 -0700 Subject: [PATCH] Clean up list media integrity check result storage --- .../Attachments/BackupListMediaManager.swift | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/SignalServiceKit/Backups/Attachments/BackupListMediaManager.swift b/SignalServiceKit/Backups/Attachments/BackupListMediaManager.swift index 97640fb72d..d2e92b191c 100644 --- a/SignalServiceKit/Backups/Attachments/BackupListMediaManager.swift +++ b/SignalServiceKit/Backups/Attachments/BackupListMediaManager.swift @@ -62,6 +62,12 @@ public struct ListMediaIntegrityCheckResult: Codable { } var hasFailures: Bool { + if fullsize.uploadedCount == 0 { + // The first time we run list media, we have no + // uploads, so don't count as a failure. + return false + } + // Don't count thumbnail failures // Don't count orphans; we maybe just haven't deleted yet. return fullsize.hasFailures @@ -132,6 +138,13 @@ public class BackupListMediaManagerImpl: BackupListMediaManager { self.orphanedBackupAttachmentStore = orphanedBackupAttachmentStore self.remoteConfigManager = remoteConfigManager self.tsAccountManager = tsAccountManager + + NotificationCenter.default.addObserver( + self, + selector: #selector(backupPlanDidChange), + name: .backupPlanChanged, + object: nil + ) } public func getLastFailingIntegrityCheckResult(tx: DBReadTransaction) throws -> ListMediaIntegrityCheckResult? { @@ -1162,6 +1175,19 @@ public class BackupListMediaManagerImpl: BackupListMediaManager { self.kvStore.removeValue(forKey: Constants.lastEnumeratedAttachmentIdKey, transaction: tx) } + @objc + private func backupPlanDidChange() { + switch db.read(block: backupSettingsStore.backupPlan(tx:)) { + case .free, .paid, .paidAsTester, .paidExpiringSoon, .disabling: + return + case .disabled: + // Rotate the last integrity check failure when disabled + db.write { tx in + kvStore.removeValue(forKey: Constants.lastNonEmptyIntegrityCheckResultKey, transaction: tx) + } + } + } + private enum Constants { /// Maps to the upload era (active subscription) when we last queried the list media /// endpoint, or nil if its never been queried.