medic / cht-core

The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
https://communityhealthtoolkit.org
GNU Affero General Public License v3.0
438 stars 209 forks source link

Make sure sync status reflects current state of the local database #7843

Open dianabarsan opened 1 year ago

dianabarsan commented 1 year ago

What feature do you want to improve? We set webapp sync status to success after a successful replication. However, this doesn't account for denied document retries. We also set the currentSeq as last replicated seq, although this might not reflect the truth, if there were database writes in the meantime (race conditions).

Describe the improvement you'd like Successful sync status should be displayed when the local (pouch) checkpointer last_seq is the same as the local database update_seq. The biggest issue with this approach is that PouchDb doesn't expose the API to get the checkpointer document id, and it may be too fragile to just iterate over _local docs to find it.

Describe alternatives you've considered

Additional context With offline user replace, but also with move contacts, it becomes important to trust the sync status completely.

dianabarsan commented 1 year ago

Related issue: https://github.com/medic/cht-core/issues/6299