From 0f8ab7693a66aee46220af7b894ad247359e0bbe Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Mon, 26 May 2025 16:02:49 +0200 Subject: [PATCH 1/2] Fix for issue #339 with iOS app not syncing when articles are deleted from the web UI. This fix was created with help from GitHub Copilot and GPT-4.1 The bug is caused by the sync logic not removing locally cached articles that have been deleted on the server (via the web UI). The root cause is the following: - The iOS app fetches all articles from the server and updates or inserts them locally. - It keeps track of the IDs of all articles received from the server in entriesSynced. - After syncing, it calls purge(), which deletes any local articles whose IDs are not in entriesSynced. - However, this purge is done in a background context and may not be saved or merged properly with the main context, or the UI may not be updated to reflect these deletions. The fix implements the following logic: - After purging deleted articles from the local database, changes are now saved and merged into the main context to ensure the UI updates and deleted articles are removed from the iOS app after a sync. Link to bug report: https://github.com/wallabag/ios-app/issues/339 --- App/Features/Sync/AppSync.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/App/Features/Sync/AppSync.swift b/App/Features/Sync/AppSync.swift index 19f61108..fa1c4366 100644 --- a/App/Features/Sync/AppSync.swift +++ b/App/Features/Sync/AppSync.swift @@ -100,6 +100,15 @@ extension AppSync { backgroundContext.delete(entryToDelete) } + // Ensure deletions are saved and changes are merged + try backgroundContext.save() + coreData.persistentContainer.viewContext.perform { + do { + try self.coreData.persistentContainer.viewContext.save() + } catch { + logger.error("Error saving main context after purge: \(error.localizedDescription)") + } + } } catch { logger.error("Error in batch delete") } From 2b85805b11d89c378b3a69bf2b92e9c56fe7e2a9 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 27 May 2025 15:51:21 +0200 Subject: [PATCH 2/2] Fix for issue #339 with iOS app not syncing when articles are deleted from the web UI. The previous fix does not solve this issue, hence submitting this one, which was more thoroughly tested. It turns out that the bug is actually an edge case: articles are not synced only when the list of articles becomes empty on the server. This is because `purge()` has a guard testing for `entriesSynced.count == 0` which prevents the sync from happening in the iOS app. This commit removes the guard, enabling the correct syncing behavior. https://github.com/wallabag/ios-app/issues/339 --- App/Features/Sync/AppSync.swift | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/App/Features/Sync/AppSync.swift b/App/Features/Sync/AppSync.swift index fa1c4366..f31221a2 100644 --- a/App/Features/Sync/AppSync.swift +++ b/App/Features/Sync/AppSync.swift @@ -86,10 +86,6 @@ extension AppSync { } private func purge() { - if entriesSynced.count == 0 { - return - } - let fetchRequest = Entry.fetchRequest() fetchRequest.predicate = NSPredicate(format: "NOT (id IN %@)", argumentArray: [entriesSynced]) @@ -100,15 +96,7 @@ extension AppSync { backgroundContext.delete(entryToDelete) } - // Ensure deletions are saved and changes are merged try backgroundContext.save() - coreData.persistentContainer.viewContext.perform { - do { - try self.coreData.persistentContainer.viewContext.save() - } catch { - logger.error("Error saving main context after purge: \(error.localizedDescription)") - } - } } catch { logger.error("Error in batch delete") }