Adds content state comparison functionality to autosave interval #95
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Issue
Because nested sub-contents do not trigger their respective XAPI verbs, which in turn trigger save events, we have tuned down out autosave interval on our server to be extremely frequent to prevent the loss of user data and progress. This is undesirable, as:
Solution
By taking advantage of the existing auto-save functionality, user data can be saved conditionally by comparing the current state of the content with a previous state of the content. If the user has in any way interacted with the content, then the user data should be set and a previous state should be assigned for the next comparison. If the states are equal and unchanged, then the setting of user data does not need to be performed. The scope of the state comparison function is as follows:
deepEq
algorithm, which recursively compares two objects and determines if they are equivalent.H5P.setUserData
function handles states) but can compare complex objects such as circular ones.Because the autosave will rely upon a state difference, the interval then becomes less honest. The cons of this implementation are that the algorithm will have to compare states based on the autosave interval, therefore increasing computational requirements given an extremely small interval and extremely large and nested state object. The pros, however, are: