Clean up list media integrity check result storage

This commit is contained in:
Harry 2025-08-29 11:58:19 -07:00 committed by GitHub
parent d6571f3fd9
commit c01cbfdeef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.