Skip to content

[DRAFT] Feature/hm 111#6

Draft
TheoAtTechStack wants to merge 3 commits intomasterfrom
feature/HM-111
Draft

[DRAFT] Feature/hm 111#6
TheoAtTechStack wants to merge 3 commits intomasterfrom
feature/HM-111

Conversation

@TheoAtTechStack
Copy link
Copy Markdown
Collaborator

@TheoAtTechStack TheoAtTechStack commented Sep 29, 2025

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:

  1. 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_id to match them.

  2. Updates are based on a timestamp. An updated_at timestamp 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.

  3. A single "upsert" operation handles changes. We use the existing cacheFhirResources function 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.

mihaipop-tsa
mihaipop-tsa previously approved these changes Sep 29, 2025
Copy link
Copy Markdown
Collaborator

@mihaipop-tsa mihaipop-tsa left a comment

Choose a reason for hiding this comment

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

LGTM

@mihaipop-tsa mihaipop-tsa dismissed their stale review October 1, 2025 07:15

Didn't realise this was a draft, will review again once it's done.

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.

3 participants