Remove online form cache - #293
Conversation
| modelStr: formParts.model, | ||
| instanceStr: _prepareInstance( formParts.model, settings.defaults ), | ||
| external: formParts.externalData, | ||
| survey: formParts, |
There was a problem hiding this comment.
While still untested, the changes in this file restore almost exactly the original behavior prior to #269, the only difference is store.init does still need to be called to support last-saved functionality. The store is otherwise not in use in this code path, but it's worth calling out.
| const uploadQueuedRecord = _uploadRecord; | ||
|
|
||
| const uploadRecord = ( survey, record ) => ( | ||
| setLastSavedRecord( survey, record ) | ||
| .then( () => _uploadRecord( record ) ) | ||
| ); | ||
|
|
There was a problem hiding this comment.
Separating these functions wasn't a strictly necessary change, but uploadRecord's signature has changed to require a survey to support last-saved functionality while online, and it felt like this separation was better than requiring that for offline mode's upload queue where last-saved should not be used anyway. An alternative approach would have been to call setLastSavedRecord in controller-webform.js, but that would have required backfilling a much more elaborate set of tests for that module.
| /** @type {Survey} */ | ||
| let survey; | ||
|
|
||
| /** @type {XMLDocument} */ |
There was a problem hiding this comment.
The changes below remove last-saved implementation details, which are now implemented in the new last-saved.js module instead.
| import $ from 'jquery'; | ||
| import encryptor from './encryptor'; | ||
| import formCache from './form-cache'; | ||
| import { getLastSavedRecord, populateLastSavedInstances } from './last-saved'; |
There was a problem hiding this comment.
I tried to keep changes here as minimal as possible, as this module is still untested. The changes here are to support:
- The signature change to
uploadRecord - Continuing to ensure last-saved instances are populated when the form is reset after submitting/queueing/saving a draft record
| import settings from './settings'; | ||
| import connection from './connection'; | ||
| import assign from 'lodash/assign'; | ||
| import encryptor from './encryptor'; |
There was a problem hiding this comment.
As with many of the changes in connection.js, the changes here remove last-saved implementation details, which are now implemented in last-saved.js.
| @@ -0,0 +1,152 @@ | |||
| import encryptor from './encryptor'; | |||
There was a problem hiding this comment.
All of the last-saved implementation now lives here. These changes should mostly look familiar, as it's very similar to the previous implementation. The primary differences are:
- Last-saved records are no longer stored in
surveys, they're written to a newlastSavedRecordsstore - Some code style changes:
- Named exports declared at the definition site; this improves the ability to follow references through the project, as well as makes it clearer at definition site whether a function is intended to be used outside the module
- Arrow functions (they're just more idiomatic)
- Not technically a change, but calling out that if a survey is already cached for offline mode, online mode will still update that cache's last-saved
externalDatainstances when a survey changes. This ensures caches do not store stale last-saved data, particularly in cases where a last-saved instance may have been removed from the form.
| import { t } from './translator'; | ||
| import $ from 'jquery'; | ||
| import formCache from './form-cache'; | ||
| import { setLastSavedRecord } from './last-saved'; |
There was a problem hiding this comment.
The changes here account for the API changes in connection.js.
| flush, | ||
| dump | ||
| dump, | ||
| get lastSavedRecords() { return server.lastSavedRecords; }, |
There was a problem hiding this comment.
I tried to keep the changes to store.js to a minimum, keeping as much last-saved logic in last-saved.js as possible. These minor changes were necessary because the store's schema all has to be defined at initialization time. This breaks a bit with the pattern for other stores, as last-saved.js references the db.js interfaces directly rather than a wrapper around them.
| ) ) | ||
| ) | ||
| ), | ||
| ], |
There was a problem hiding this comment.
This change, as well as the one in build.js, addresses another media regression (and potentially several other regressions 😬), this time caused by #289:
enketo-coredefines and implements a set of aliased modules whose functionality it depends onenketo-expressalso defines those aliases, but overrides those implementations.- When we switched to esbuild, it failed to account for those overrides, causing the
enketo-expressbuild to useenketo-core's behavior for those modules.
There was a problem hiding this comment.
We should consider consolidating relevant portions of these configs, so the two builds don't diverge in the future.
| } ) | ||
| .then( done, done ); | ||
| } ); | ||
| } ); |
There was a problem hiding this comment.
These tests are no longer relevant, because none of the modes access the form cache anymore.
4c8cc15 to
a367b71
Compare
|
Hi @eyelidlessness, I had a quick glance and especially at the PR comments you made. Looks good. There is just a merge conflict atm. I'd like to do some real-life testing in the next few days. |
I committed these by mistake in a rush to get the draft PR open
Also brings in the remaining relevant update test from enketo#291
This resolves issues where media was being removed from a form when saving a record in offline mode
- Don't error when submitting an edit - Don't set/update a last-saved record when submitting an edit
20cd8ab to
f09f101
Compare
|
@MartijnR sorry it took a bit to resolve conflicts. Rebase got pretty confusing 😬 but should be good to go now! |
|
Since some other related issues need fixing before releasing a new version, I will just go ahead and merge. |
|
In a short while if there are no objections raised.... |
|
We’ve got some quality assurance planned in the next few days but if you’re satisfied with your checks a release would be most appreciated! |
|
Oh, that would be great. Now I am tempted to just wait... :) |
|
That sounds fine to me! @eyelidlessness would waiting a few days make more conflicts accumulate? @getodk/testers are back from vacation on Tues of next week. |
|
I hope not but I don't mind dealing with them if they do, if holding off is preferred! |
f09f101 to
d387d45
Compare
This change addresses problems introduced in #269:
lastSavedRecordsstore.jr:URL, which will be addressed separately to resolve Media files with spaces in their filename do not load enketo#1101)