From 74ed8c2534e2b57a15edd6da7fee22bce1525e04 Mon Sep 17 00:00:00 2001 From: Harry <109690906+harry-signal@users.noreply.github.com> Date: Wed, 15 Oct 2025 13:25:52 -0700 Subject: [PATCH] Fix deserialization of old integrity checks --- .../Attachments/BackupListMediaManager.swift | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/SignalServiceKit/Backups/Attachments/BackupListMediaManager.swift b/SignalServiceKit/Backups/Attachments/BackupListMediaManager.swift index 8b48a27fd6..8ab1315bab 100644 --- a/SignalServiceKit/Backups/Attachments/BackupListMediaManager.swift +++ b/SignalServiceKit/Backups/Attachments/BackupListMediaManager.swift @@ -20,18 +20,18 @@ public struct ListMediaIntegrityCheckResult: Codable { /// Count of attachments we expected to see on CDN but did not. /// This count is "bad". public fileprivate(set) var missingFromCdnCount: Int - public fileprivate(set) var missingFromCdnSampleAttachmentIds = Set() + public fileprivate(set) var missingFromCdnSampleAttachmentIds: Set? = Set() /// Count of attachments that exist locally, are eligible for upload, are not marked /// uploaded, are not on the CDN, and therefore _should_ be in the upload /// queue but are not in the upload queue. /// This count is "bad". public fileprivate(set) var notScheduledForUploadCount: Int = 0 - public fileprivate(set) var notScheduledForUploadSampleAttachmentIds = Set() + public fileprivate(set) var notScheduledForUploadSampleAttachmentIds: Set? = Set() /// Count of attachments we did not expect to see on CDN but did see. /// This count can be "bad" because it could indicate a bug with local state management, /// but it could happen in normal edge cases if we just didn't know about a completed upload. public fileprivate(set) var discoveredOnCdnCount: Int - public fileprivate(set) var discoveredOnCdnSampleAttachmentIds = Set() + public fileprivate(set) var discoveredOnCdnSampleAttachmentIds: Set? = Set() static var empty: Result { return Result(uploadedCount: 0, ineligibleCount: 0, missingFromCdnCount: 0, discoveredOnCdnCount: 0) @@ -41,8 +41,8 @@ public struct ListMediaIntegrityCheckResult: Codable { return missingFromCdnCount > 0 || notScheduledForUploadCount > 0 || discoveredOnCdnCount > 0 } - mutating func addSampleId(_ id: Attachment.IDType, _ keyPath: WritableKeyPath>) { - var sampleIds = self[keyPath: keyPath] + mutating func addSampleId(_ id: Attachment.IDType, _ keyPath: WritableKeyPath?>) { + var sampleIds = self[keyPath: keyPath] ?? Set() if sampleIds.count >= 10 { // Only keep 10 ids return @@ -1510,26 +1510,26 @@ private class ListMediaIntegrityCheckerImpl: ListMediaIntegrityChecker { Logger.info("\(_result.thumbnail.ineligibleCount) ineligible attachments") if _result.fullsize.missingFromCdnCount > 0 { shouldNotify = true - Logger.error("Missing fullsize uploads from CDN, samples: \(_result.fullsize.missingFromCdnSampleAttachmentIds)") + Logger.error("Missing fullsize uploads from CDN, samples: \(_result.fullsize.missingFromCdnSampleAttachmentIds ?? Set())") } if _result.fullsize.notScheduledForUploadCount > 0 { shouldNotify = true - Logger.error("Unscheduled fullsize uploads, samples: \(_result.fullsize.notScheduledForUploadSampleAttachmentIds)") + Logger.error("Unscheduled fullsize uploads, samples: \(_result.fullsize.notScheduledForUploadSampleAttachmentIds ?? Set())") } if _result.fullsize.discoveredOnCdnCount > 0 { shouldNotify = true - Logger.error("Discovered fullsize upload on CDN, samples: \(_result.fullsize.discoveredOnCdnSampleAttachmentIds)") + Logger.error("Discovered fullsize upload on CDN, samples: \(_result.fullsize.discoveredOnCdnSampleAttachmentIds ?? Set())") } // Don't notify for thumbnail issues. if _result.thumbnail.missingFromCdnCount > 0 { - Logger.warn("Missing thumbnail uploads from CDN, samples: \(_result.thumbnail.missingFromCdnSampleAttachmentIds)") + Logger.warn("Missing thumbnail uploads from CDN, samples: \(_result.thumbnail.missingFromCdnSampleAttachmentIds ?? Set())") } if _result.thumbnail.notScheduledForUploadCount > 0 { - Logger.warn("Unscheduled thumbnail uploads, samples: \(_result.thumbnail.notScheduledForUploadSampleAttachmentIds)") + Logger.warn("Unscheduled thumbnail uploads, samples: \(_result.thumbnail.notScheduledForUploadSampleAttachmentIds ?? Set())") } if _result.thumbnail.discoveredOnCdnCount > 0 { - Logger.warn("Discovered thumbnail upload on CDN, samples: \(_result.thumbnail.discoveredOnCdnSampleAttachmentIds)") + Logger.warn("Discovered thumbnail upload on CDN, samples: \(_result.thumbnail.discoveredOnCdnSampleAttachmentIds ?? Set())") } if _result.orphanedObjectCount > 0 {