Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix synchronous data removal from PixelDataStore cache #382

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions DuckDuckGo/Statistics/PixelDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ final class LocalPixelDataStore<T: NSManagedObject>: PixelDataStore {
}

func removeValue(forKey key: String, completionHandler: ((Error?) -> Void)?) {
self.cache.removeValue(forKey: key)
let predicate = self.predicate(forKey: key)

func mainQueueCompletion(_ error: Error?) {
Expand All @@ -185,8 +186,6 @@ final class LocalPixelDataStore<T: NSManagedObject>: PixelDataStore {
let changes: [AnyHashable: Any] = [NSDeletedObjectsKey: deletedObjects]
NSManagedObjectContext.mergeChanges(fromRemoteContextSave: changes, into: [context])

self.cache.removeValue(forKey: key)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the odds that the try call earlier in this function fails? In that case, we'll have data removed from the cache but not from the DB. Is it worth repairing the cache in the catch block in case this happens? Admittedly I think the chances are slim.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cache is the source of truth here and if we get an error here it would be the database that needs to be restored - we've discussed this on our last Apple team meeting and this will be handled as a separate task


mainQueueCompletion(nil)
} catch {
mainQueueCompletion(error)
Expand Down