Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localize change sync operations #4070

Merged
merged 21 commits into from
May 31, 2023

Conversation

rtibbles
Copy link
Member

Summary

Description of the change(s) you made

  • Attempts to prevent issues with background tabs sleeping timers and saving memory by making each tab responsible for the creation and persistence to the backend of edits made in the tab context
  • Creates Change classes mapping to each Change type to handle proper instantiation of the change and persistence to the indexedDB changes table
  • Updates all put operations to be add operations (new in Dexie v3) to make explicit create vs update changes
  • Adds change creation logic into add, update, and delete methods
  • Updates existing move, copy, publish, sync, and deploy changes to use the new Change classes
  • Removes unused methods on the resource class that modify tables, to prevent future developers from using them without the appropriate change updates
  • Updates the server sync logic to run in every open tab (but only to poll when the window is visible)
  • Updates the debounce behaviour to remove need for the syncActive flag, and instead chain from previous invocations
  • Updates the debounce behaviour to always return a promise that will resolve with the next sync
  • Updates the forceServerSync function to try to persist all currently unsynced changes, as a last resort before someone logs out.
  • Activates the service worker to be active during development (this was not ultimately needed for the implementation, and can be dropped if not wanted)

Manual verification steps performed

  1. Make edits to nodes
  2. Upload new nodes
  3. Open multiple tabs, make changes in each, ensure that changes from each tab sync from within the tab

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:

  • If this is an important user-facing change, PR or related issue the CHANGELOG label been added to this PR. Note: items with this label will be added to the CHANGELOG at a later time
  • If this includes an internal dependency change, a link to the diff is provided
  • The docs label has been added if this introduces a change that needs to be updated in the user docs?
  • If any Python requirements have changed, the updated requirements.txt files also included in this PR
  • Opportunities for using Google Analytics here are noted
  • Migrations are safe for a large db

Studio-specifc:

  • All user-facing strings are translated properly
  • The notranslate class been added to elements that shouldn't be translated by Google Chrome's automatic translation feature (e.g. icons, user-generated text)
  • All UI components are LTR and RTL compliant
  • Views are organized into pages, components, and layouts directories as described in the docs
  • Users' storage used is recalculated properly on any changes to main tree files
  • If there new ways this uses user data that needs to be factored into our Privacy Policy, it has been noted.

Testing:

  • Code is clean and well-commented
  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Any new interactions have been added to the QA Sheet
  • Critical and brittle code paths are covered by unit tests

Reviewer's Checklist

This section is for reviewers to fill out.

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

Copy link
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I like this a lot! I left a bunch of comments with my thoughts. My only requested changes though are to fix the service worker issue and to reinstate source tracking, since usages of it are failing on this.

this.setAndValidateNotUndefined(target, 'target');
this.setAndValidateLookup(position, 'position', RELATIVE_TREE_POSITIONS_LOOKUP);
this.setAndValidateNotUndefined(parent, 'parent');
this.setChannelAndUserId();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

contentcuration/contentcuration/views/pwa.py Show resolved Hide resolved
return !isUndefined(this.channel_id) || !isUndefined(this.user_id);
}

setChannelAndUserId(obj) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

const commonFields = ['type', 'key', 'table', 'rev', 'channel_id', 'user_id'];
const objectFields = ['objs', 'mods'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the topic of misspellings... 💯

@rtibbles
Copy link
Member Author

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.

Copy link
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things have regressed:

  1. 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)
  1. 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": []
}
  1. Using yarn run build and yarn 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)
  1. 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.
@rtibbles
Copy link
Member Author

I have fixed 1 and 4, but have not been able to replicate 2 or 3.

Copy link
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bjester bjester merged commit 743364c into learningequality:unstable May 31, 2023
9 checks passed
@rtibbles rtibbles deleted the where_is_my_mind branch May 31, 2023 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening multiple tabs may prevent proper syncing of channel changes
2 participants