PharmaLedger-IMI / ctr-workspace

UC8 Clinical Trials Recruitment
MIT License
2 stars 0 forks source link

PWA cache refresh workaround #68

Open joaoluis-pdm opened 2 years ago

joaoluis-pdm commented 2 years ago

Current situation requires the patient-ssapp to be loaded in "Chrome Incognito" mode (or firefox with debug and disable-cache=on), otherwise, it is very likely that some files are loaded from a previous release of the patient-ssapp.

This is not acceptable for a pilot.

Experiment with workarounds, such as removing all service-worker caches:

  console.log("Going to delete all caches");
  caches.keys().then( (keyList) => {
    keyList.forEach( (key) => {
      console.log("deleting cache", key);
      caches.delete(key);
    });
  });

This workaround has been tested with some success (no mobile tests where performed) at commit a61bda8af752723dbce617cae76e31dbd5b5ea23 and reverted at commit 691bf2c9f2eeac3c27598debb32459c8992811ec

PS: (Later inspection shown that) There is a method in https://github.com/PharmaLedger-IMI/ctr-workspace/blob/df3c5cd75960b684cef856bb07b5932ee23f8803/ctr-patient/pdm-trust-loader/src/scripts/services/NavigatorUtils.js#L200 that could be called for that purpose.

Could the cache be cleared every time that a version change is detected ? (Ex: From site, version v1.12.1 is provided, but localstorage says that last used version is v1.11.9 - if site and localstorage differ, cache could be cleared). ( Had no success yet with experiments using tricks such as https://stackoverflow.com/questions/49739438/when-and-how-does-a-pwa-update-itself )

First, let's try the changes to https://github.com/PharmaLedger-IMI/ctr-workspace/blob/231645e712d9949d153899be84d151fb54ee874f/ctr-patient/trust-loader-config/patient-ssapp/loader/environment.js

joaoluis-pdm commented 2 years ago

Meeting with Rafael (in the scope of CSC). Using the new trust-loader. SW are disabled. swBoot.js is still used, but for the application, the serviceWorkers are disabled.

joaoluis-pdm commented 2 years ago

pdm-trust-loader/src/assets/pwa/pwa.js

https://github.com/PharmaLedger-IMI/ctr-workspace/blob/f2ca50d970b8261d1b7d64aeacd714ea73b62df5/ctr-patient/pdm-trust-loader/src/assets/pwa/pwa.js seems up-to-date with https://github.com/PrivateSky/trust-loader/blob/a4531f65f7b1f36392ca85305b258b8680007b8c/assets/pwa/pwa.js

(Only whitespace differences on pwa.js)

ctr-patient/pdm-trust-loader/src/swLoader.js

Compared with https://github.com/PrivateSky/trust-loader/blob/a4531f65f7b1f36392ca85305b258b8680007b8c/swLoader.js

No functional differences.

pdm-trust-loader/src/scripts controllers and services

Differs a lot from current https://github.com/PrivateSky/trust-loader/tree/a4531f65f7b1f36392ca85305b258b8680007b8c/controllers and services.

Let's start with the services:

https://github.com/PrivateSky/trust-loader/blob/a4531f65f7b1f36392ca85305b258b8680007b8c/controllers/services/EventMiddleware.js

Ño functional differences. Updated anyway on CTR commit 201627b

https://github.com/PharmaLedger-IMI/ctr-workspace/blob/55801b1be158ba60e618fda35653cb645b851c79/ctr-patient/pdm-trust-loader/src/scripts/services/WalletService.js

Never existed on CTR, but seems to be an old version of https://github.com/PharmaLedger-IMI/ctr-workspace/blob/55801b1be158ba60e618fda35653cb645b851c79/ctr-patient/pdm-trust-loader/src/scripts/services/LoaderService.js

https://raw.githubusercontent.com/PrivateSky/trust-loader/2ba38dd623498d2c452812ff855876b8e91e7a2a/controllers/services/NavigatorUtils.js

Seems functionally identical to https://github.com/PharmaLedger-IMI/ctr-workspace/blob/55801b1be158ba60e618fda35653cb645b851c79/ctr-patient/pdm-trust-loader/src/scripts/services/NavigatorUtils.js (CTR uses a different singleton access function getNavigatorUtils(env), while PSK uses LOADER_GLOBALS).

joaoluis-pdm commented 2 years ago

Basically, the commit dd8e3b7 has all the updates apparently needed. More tests will come along v0.10.7

joaoluis-pdm commented 2 years ago

Site loading Benchmarks for TST v0.10.3 (sw=true, pwa=true) DEV v0.10.7 (sw=false, pwa=false) DEV v0.10.8 (sw=false, pwa=true)

Time from clickcking on the "Patient Wallet" purple box, until the dashboard is shown. (Discount +/- 1.0 seconds to click on the LOGIN button). (Also note that in the CTR Dashboard, the previous match requests are shown as "? ? ?" while the DB is not initialized. That takes longer, and A blank browser profile is created before the test. The test was run on WiFi over a vodefone.pt home network. (National routing to ARTelecom should have good performance).

firefox 95.0.1 (linux / Gnome+Ubuntu 20):

DEV v0.10.8 - 8.2 seconds (until dashboard available), ... a lot more (+/- 30 seconds) until it fetches all files from server DEV v0.10.7 - 8.6 seconds (first attempt seemed a bit more. Some sort of transparent cache somewhere ?) TST v0.10.3 - 17.0 seconds

chrome 96.0 (linux / Gnome+Ubuntu 20):

DEV v0.10.8 - 11.x seconds (until dashboard available), 24.8 seconds (until question to install) DEV v0.10.7 - 8.2 seconds TST v0.10.3 - 14.6 seconds (please discount +/- 1.0 seconds to answer "Cancel" for the extra question of choosing to install the app)

chrome mobile 96.0 - Android 10 ; Fairphone3 - browser history and cached images and files cleared before test

DEV v0.10.8 - 18.0 seconds until dashboard is available, 1m38 seconds until the question to install the PWA, 12.1 seconds to open the installed PWA. DEV v0.10.7 - 12.0 seconds (first attempt without cache clear never finished - never transition from PWA to non-PWA ?) TST v0.10.3 - 28.5 seconds (please discount +/- 1.0 seconds to answer "Cancel" for the extra question of choosing to install the app)

PS: On chrome mobile 96.0 - Android 10 ; Fairphone3 using a throttled proxy ngrok.io (at 40 req per minute) it took +/- 45 seconds to open the dashboard (without DB initialization), but it took + than 5 min to finish doing HTTPS GET requests. This was on a v0.10.8 candidate with sw=false+pwa=true.

joaoluis-pdm commented 2 years ago

This is not quite closed, as in firefox we are getting these errors: image

joaoluis-pdm commented 2 years ago

e993dbe v0.10.12 has an experimental version on queryParam patient-ssapp/loader/?v=0.10.12 Let's see how it affects installation on mobile application.