Localize change sync operations#4070
Conversation
contentcuration/contentcuration/frontend/shared/data/changes.js
Outdated
Show resolved
Hide resolved
contentcuration/contentcuration/frontend/shared/data/changes.js
Outdated
Show resolved
Hide resolved
| this.setAndValidateNotUndefined(target, 'target'); | ||
| this.setAndValidateLookup(position, 'position', RELATIVE_TREE_POSITIONS_LOOKUP); | ||
| this.setAndValidateNotUndefined(parent, 'parent'); | ||
| this.setChannelAndUserId(); |
There was a problem hiding this comment.
This feels slightly awkward because some indexeddb resources lookup the channel from a passed object, which this supports, but others use getChannelFromChannelScope. Maybe each resource/table should be able to subclass its own change with these specific implementation details. That could make sense as Move and Copy are just applicable to content nodes.
There was a problem hiding this comment.
It felt a bit awkward to have TABLE X CHANGE_TYPE changes defined, but I agree that the way this defers to the Resource classes is also awkward.
| return !isUndefined(this.channel_id) || !isUndefined(this.user_id); | ||
| } | ||
|
|
||
| setChannelAndUserId(obj) { |
There was a problem hiding this comment.
No need to change, just conversely to the constructor args, this appears to require the obj parameter when it doesn't always get one! (another comment later on)
| throw error; | ||
| } | ||
| this[name] = mapper(value); | ||
| } |
There was a problem hiding this comment.
I think these setAndValidate* are fine, but another approach could be to set, then validate later, perhaps in saveChange. One benefit would be that the property setting would be more direct, and we could have better IDE visibility in avoiding misspellings in name which must be a string in this approach.
There was a problem hiding this comment.
Yeah, I think generally it would be better to separate this - I do like the Vue props convention for specifying types, so it may be just separating out the specification of what value should be what, and setting of it would be good - then just having a validate method that runs through all of them.
| let syncActive = false; | ||
|
|
||
| const commonFields = ['type', 'key', 'table', 'rev', 'channel_id', 'user_id']; | ||
| const objectFields = ['objs', 'mods']; |
There was a problem hiding this comment.
On the topic of misspellings... 💯
contentcuration/contentcuration/frontend/shared/data/serverSync.js
Outdated
Show resolved
Hide resolved
|
All blocking comments addressed, and some of the non-blocking ones. I had some issues after rolling back migrations, so have done limited manual testing of the frontend changes, but have added additional automated test coverage. |
bjester
left a comment
There was a problem hiding this comment.
Some things have regressed:
- Clipboard to topic tree is failing in any manner:
TypeError: Cannot set properties of undefined (setting 'excluded_descendants')
From previous:
at Ce.n (http://localhost:8080/static/studio/channel_edit-f6c623f34530982ac14f.js:8:2804215)
at TreeResource.resolveTreeInsert (http://localhost:8080/static/studio/channel_edit-f6c623f34530982ac14f.js:11:20010)
at TreeResource.copy (http://localhost:8080/static/studio/channel_edit-f6c623f34530982ac14f.js:11:21939)
at Store.copyContentNode (http://localhost:8080/static/studio/channel_edit-f6c623f34530982ac14f.js:11:81114)
at Array.<anonymous> (http://localhost:8080/static/studio/channel_edit-f6c623f34530982ac14f.js:8:2479400)
at Store.dispatch (http://localhost:8080/static/studio/channel_edit-f6c623f34530982ac14f.js:8:2481965)
at Store.dispatch (http://localhost:8080/static/studio/channel_edit-f6c623f34530982ac14f.js:8:2475079)
at local.dispatch (http://localhost:8080/static/studio/channel_edit-f6c623f34530982ac14f.js:8:2477925)- Restoring a node from a trash results in errored change (seems the node vanished from trash too):
{
"disallowed": [],
"allowed": [],
"changes": [],
"errors": [
{
"key": "4109fbff224042dd92352f4b69302531",
"errors": [
"[ErrorDetail(string='Specified node does not exist', code='invalid')]"
],
"target": "2c1738cc81004c1785a5a07e24b84733",
"position": "last-child",
"server_rev": 250,
"table": "contentnode",
"type": 4,
"channel_id": "02df1a9833f64d279039f71f5045febb",
"user_id": null,
"created_by_id": 1
}
],
"successes": [],
"tasks": []
}- Using
yarn run buildandyarn run runserver, after I cleared the site data, this is persisting after refreshing:
Uncaught (in promise) bad-precaching-response: bad-precaching-response :: [{"url":"http://localhost:8080/static/studio/128-128-159012dface3864c747f.js","status":404}]
at PrecacheStrategy._handleInstall (http://localhost:8080/serviceWorker.js:5:13559)
at async PrecacheStrategy._handle (http://localhost:8080/serviceWorker.js:5:12588)
at async PrecacheStrategy._getResponse (http://localhost:8080/serviceWorker.js:5:11149)- Adding a new question to an exercise:
TypeError: (intermediate value).add is not a function
at Resource.add (http://localhost:8080/static/studio/channel_edit-f6c623f34530982ac14f.js:11:27422)Add more finegrained error catching for applying remote changes.
Always set syncActive to `false` when finished.
Clean up unused active channel monitoring logic.
… object. Ensure we generate changes that require the old object representation before modifying. Ignore null changes.
Update tests with appropriate mocks to handle this.
from Dexie Observable.
|
I have fixed 1 and 4, but have not been able to replicate 2 or 3. |
c6385e8 to
05fccf0
Compare
bjester
left a comment
There was a problem hiding this comment.
I'm still getting (3) but the other things are fixed so I don't know that it's breaking anything! 🎉
Ran through the different edit operations and everything seems good
Summary
Description of the change(s) you made
putoperations to beaddoperations (new in Dexie v3) to make explicit create vs update changesadd,update, anddeletemethodssyncActiveflag, and instead chain from previous invocationsManual verification steps performed
Reviewer guidance
Are there any risky areas that deserve extra testing?
I think the main area for concern here is that it feels like there is more of a chance of a change not getting synced, because a page could be refreshed etc. Not sure how to make sure changes do get synced, while also maintaining the separation of tabs syncing their own changes.
References
Hopefully fixes #3992
Contributor's Checklist
PR process:
CHANGELOGlabel been added to this PR. Note: items with this label will be added to the CHANGELOG at a later timedocslabel has been added if this introduces a change that needs to be updated in the user docs?requirements.txtfiles also included in this PRStudio-specifc:
notranslateclass been added to elements that shouldn't be translated by Google Chrome's automatic translation feature (e.g. icons, user-generated text)pages,components, andlayoutsdirectories as described in the docsTesting:
Reviewer's Checklist
This section is for reviewers to fill out.
yarnandpip)