Draft
Conversation
…dated date check [HM-111]
Didn't realise this was a draft, will review again once it's done.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Sync Logic Changes
Previously, the app's sync function would fetch all data from the server and completely overwrite the local database. We've replaced this with a more intelligent incremental merge strategy.
Now, when a sync is initiated:
Incoming data is compared to local data. The app fetches the latest records from the server and compares them against the records already stored on the device, using the
resource_idto match them.Updates are based on a timestamp. An
updated_attimestamp is used to determine if a change is needed. An existing record is only updated if the incoming version is newer. This prevents unnecessary database writes and improves performance.A single "upsert" operation handles changes. We use the existing
cacheFhirResourcesfunction to efficiently handle both creating new records (if the ID doesn't exist locally) and updating existing ones (if the incoming record is newer).In short, the sync logic no longer blindly replaces data. It now performs a smart, row-by-row merge that preserves your local database, adds new records, updates only what has changed, ensuring data is always consistent and up-to-date without unnecessary data loss.