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
467 stars 217 forks source link

Update the webapp upgrade process to avoid partial upgrades #7146

Open dianabarsan opened 3 years ago

dianabarsan commented 3 years ago

What feature do you want to improve? Currently, an upgrade of the webapp on a client consists of two events:

  1. syncing _design/medic-client
  2. updating the service worker (which is triggered by syncing service-worker-meta)

A partial upgrade is a state where only one of these events have happened, with the second event happening in the (hopefully) near future. Being in a partially upgraded state can pose problems, for example, if the code (event 2) is updated and running before the ddoc, the code could be accessing new views, or generating data (tasks for example) using old view code. Theoretically, a plethora of issues could happen when the client is in this state.

Describe the improvement you'd like Figure out a way to package the upgrade in a single step.

Describe alternatives you've considered Leave it as it is.

Additional context We've recently received reports from production servers where there is proof (telemetry and feedback docs) that clients had downloaded the code, and ran this code, before downloading the ddoc. Example: https://github.com/medic/config-vhw/issues/48#issuecomment-854704181

dianabarsan commented 1 year ago

After implementing the Nairobi replication protocol, achieving this becomes much easier because when syncing, we have an overview of every document that needs updating and we can choose which ones to prioritize.

I think the solution would be to always download changes for "important" documents first (settings, ddoc and service worker) and download the rest later.

This way we can make be more convinced that when a user gets the update popup, the upgrade was complete.