Multiple save calls on page load and submissions

Forums: 

I have recently encoutered 2 issues on a client's website that causes a lot of unnecessary save calls to the backend (admin_ajax.php h5p_contents_user_data post request).

The first issue is that when a user loads a page with multiple H5P content blocks in it, every one of them calls the save function in h5p.js. This can cause an extreme ammount of save calls to the server if multiple users load a new page at the same time.

The second issue is hard to test for and i haven't found a way to reliably trigger it. But sometimes when an answer is submitted is causes multiple H5P content blocks on the page to also trigger a save. This again can cause an extreme ammount of requests.

I think i have found a fix for both of these of these issues, although it needs more testing. By saving the initial state of a content block on page load an extra check can be added before saving to see if the state has changed from the original. This will make sure that when the save function it called it is actually done because a user changed something.

The way i implented it is by adding an initial state to line 227 in h5p.js: var initialState = instance.getCurrentState();

And by changing the check in line 230: if (state !== undefined && JSON.stringify(state) !== JSON.stringify(initialState)) {

I don't know if this is the right place to post this, but i hope something like this could be implemented in a future WordPress plugin update.

otacke's picture

Hi!

I think checking for actual changes is something that `H5P.setUserData` should so already. Some (I don't know the exact number) content types currently return some value even if nothing was changed, and that behaviour was changed across content types throughout the last week - for some other reason, but that doesn't matter :-) So, the issue should be resolved once the updates of the content types are released.

Cheers,
Oliver

Hey Oliver,

Thanks for the update! We'll be checking out the new update once it releases to see if it fixes our issues.