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

Conversation

mallexxx
Copy link
Collaborator

Task/Issue URL:
Tech Design URL:
CC:

Description:
Fixes Pixel Data Store Cached value available after removing a value from PixelDataStore (and later data race when removing the value from background thread)

Steps to test this PR:

  1. Validate PixelDataStore.remove(valueForKey: ..) removes the value from cache synchronously

Testing checklist:

  • Test with Release configuration

Internal references:

Software Engineering Expectations
Technical Design Template
When ready for review, remember to post the PR in MM

@mallexxx mallexxx requested a review from tomasstrba December 20, 2021 11:44
Copy link
Collaborator

@samsymons samsymons left a comment

Choose a reason for hiding this comment

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

LGTM, good call moving this up front. Added one question, though up to you whether to take action on it. 🙂

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

@samsymons samsymons assigned samsymons and mallexxx and unassigned samsymons Dec 22, 2021
@mallexxx mallexxx merged commit 5091379 into develop Dec 22, 2021
@mallexxx mallexxx deleted the alex/fix-pixel-cache-data-removal branch December 22, 2021 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants