Skip local-folder watches from iCloud sync

This commit is contained in:
Arkadiusz Fal
2026-05-09 15:53:54 +02:00
parent c64f13a0e6
commit d49591eaf4

View File

@@ -628,9 +628,24 @@ final class CloudKitSyncEngine: @unchecked Sendable {
// MARK: - WatchEntry Sync Operations
/// Whether a watch entry is eligible for iCloud sync.
/// Local-folder media plays from a per-device path, so syncing its watch progress
/// to other devices (where the file is not reachable) is wasted noise.
private func shouldSyncWatchEntry(sourceRawValue: String, externalExtractor: String?) -> Bool {
!(sourceRawValue == "extracted" && externalExtractor == MediaFile.localFolderProvider)
}
private func shouldSyncWatchEntry(_ watchEntry: WatchEntry) -> Bool {
shouldSyncWatchEntry(sourceRawValue: watchEntry.sourceRawValue, externalExtractor: watchEntry.externalExtractor)
}
/// Queue a watch entry for sync (debounced).
func queueWatchEntrySave(_ watchEntry: WatchEntry) {
guard canSyncPlaybackHistory else { return }
guard shouldSyncWatchEntry(watchEntry) else {
LoggingService.shared.logCloudKit("Skipping local-folder watch entry: \(watchEntry.videoID)")
return
}
Task {
let record = await recordMapper.toCKRecord(watchEntry: watchEntry)
@@ -686,6 +701,7 @@ final class CloudKitSyncEngine: @unchecked Sendable {
// Get all local watch history (limit to reasonable amount)
let watchHistory = dataManager.watchHistory(limit: 5000)
.filter { shouldSyncWatchEntry($0) }
guard !watchHistory.isEmpty else {
LoggingService.shared.logCloudKit("No local watch history to upload")
@@ -2100,6 +2116,11 @@ extension CloudKitSyncEngine: CKSyncEngineDelegate {
guard canSyncPlaybackHistory else { return .success }
let watchEntry = try await recordMapper.toWatchEntry(from: record)
guard shouldSyncWatchEntry(watchEntry) else {
LoggingService.shared.logCloudKit("Ignoring incoming local-folder watch entry: \(watchEntry.videoID)")
return .success
}
// Check if exists locally
if let existing = dataManager.watchEntry(for: watchEntry.videoID) {
// Conflict - resolve it