Move the reset_all_state() to cron job?

Move the reset_all_state() to cron job?

by Alexander Vandev -
Number of replies: 3

Hi everybody,

I am supporting a moodle (version 3.9) and with growing in students and courses I see that saving on editing courses start to become slow.

From my research I found that this is due to reset_all_state() method in:

course/modlib.php

Which is called from:

course/modedit.php

When I disable the "Completion tracking" from admin it works fast.

So I decide to give the job of resetting to a cron as a solution.

My plan is when a course is edited, instead of doing reset at this moment, to replace it with a simple db insert into one new queue table with the params that are send to reset_all_state().

And the course is saved super fast as when "Completion tracking" is turned off.

Then in the background the cron will execute all the logic from reset_all_state() including delete and purge, which make it slow.

Have anybody tried such approach or there is a better solution to speed up the reset part?

Thank you in advance.

Average of ratings: -
In reply to Alexander Vandev

Re: Move the reset_all_state() to cron job?

by Alexander Vandev -
Hi,

I've implemented it and even made 2 crons:
- a light one (that do only purge)
- a full reset (all reset logic)

The result is great, saving course is happening now for couple of seconds and the reset/purge is done in the background by the cron.

On course save I put some details in db queue table, from which the cron reads. Cron took a record, work on in it and on success deletes the record from the queue table.
Till now didn't catch any negative effect from putting the reset/purge to be done in the background.

If anybody is interested implementing it, I can share the logic.

;)
Average of ratings: Useful (1)
In reply to Alexander Vandev

Re: Move the reset_all_state() to cron job?

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Hi Alexander,

This seems interesting. I think you should create a tracker issue for that, and provide your code in it. You should ensure it also works with latest Moodle versions.

This way, it could probably be integrated in future Moodle versions.

Séverin