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

Feature/icloud sync #763

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Deadpikle
Copy link
Contributor

@Deadpikle Deadpikle commented Oct 12, 2024

Uses NSUbiquitousKeyValueStore (link) to sync data between devices.

NSUbiquitousKeyValueStore allows for a max of 1 MB of data. I did a quick Excel check. WaniKani has a little less than or around 10,000 items. With max 25-byte pieces of data (subject ID and recent mistake time), we can store nearly 42,000 pieces of data, which is more than enough. Given that a user will probably have less than a 1,000 recent mistakes at any time (if they're super behind AND mess up a bunch), we are fine just using KVS instead of syncing a JSON file as thought about in #761.

If we need more space in the KVS for some odd reason in the future, we can compress the data slightly to save bytes. Again, I doubt we will ever reach any significant capacity for this feature, so it's likely nothing to worry about.

I successfully used this to sync recent mistakes from one iOS Simulator to another.

The one odd scenario at first glance here is as follows:

  1. Device A uploads new recent mistakes
  2. Device B starts.
  3. Before device B can download recent mistake data, it thinks there are no mistake, calls updateRecentMistakesInCloud, and says there are no recent mistakes. (Note that setting a key will not trigger the notification for data changed as outlined here in the docs.)
  4. Intuition might say we just hit a race condition, and I suppose we sort of did, BUT iCloud seems to be smart and still calls the notification for the key store changing from device A with the updated data in the preferences object, so everything syncs OK, at least in my test. (Even if the cloud data overwrites local data, since we still have the local data in the db and merge everything together, it all works out regardless.)
  5. Once we get updated data from the cloud, in case we uploaded "bad data" previously OR if there is newer data the cloud didn't know about, we again update the KVS data, completing a full sync.

Closes #761

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.

Feature: Syncing recent mistakes
1 participant