Cron Job: Deleting Old Quizzes

Cron Job: Deleting Old Quizzes

- John Ivan Abella の投稿
返信数: 4

We made a custom plugin so that we can delete old quizzes (1-2 months old). However it takes long even for just 1 quiz. The attachment displays the runtime comparison when deleting a quiz in the actual interface with moodle and in the custom plugin.We have created a custom plugin to delete old quizzes (1-2 months old). However, it is taking a long time to delete even just one quiz. The attachment shows the comparison of the runtime when deleting a quiz in the standard Moodle interface and in our custom plugin. The problem is there's a thousand of quizzes and it will take long to delete all of them. We have developed a custom plugin to delete quizzes that are 1-2 months old. However, it is taking a long time to delete even just one quiz. The attachment provides a comparison of the runtime when deleting a quiz using the standard Moodle interface versus our custom plugin. The issue is that there are thousands of quizzes, and it will take a significant amount of time to delete all of them.

添付 test.png
John Ivan Abella への返信

Re: Cron Job: Deleting Old Quizzes

- Howard Miller の投稿
画像 Core developers 画像 Documentation writers 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 Plugin developers
Is there a question, here? We can't debug your code without seeing your code and, even then, it's unlikely somebody is going to do that.

XDebug profiling is generally your friend for this sort of thing. Also, check your SQL queries - are you querying huge tables and missing indexes? 'Explain' is your friend in that case.
Howard Miller への返信

Re: Cron Job: Deleting Old Quizzes

- John Ivan Abella の投稿
Apologize for my initial writing. That was weird.
 
To give a bit more context, we developed a custom plugin called Quiz Builder for review purposes. Then, we added a scheduled task to automate the deletion of quizzes that are 1-2 months old because manually deleting them through the standard Moodle interface was too time-consuming. However, the scheduled task still takes an unexpectedly long time to delete even a single quiz, and we have thousands to delete.

Here is a snippet of the relevant part of our code:
image.png
 
If you or anyone else has more insights into how we might optimize this process or if there are specific things we should be looking out for, I'd greatly appreciate it. Thank you
John Ivan Abella への返信

Re: Cron Job: Deleting Old Quizzes

- Howard Miller の投稿
画像 Core developers 画像 Documentation writers 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 Plugin developers
Try,

course_delete_module($quiz->quizmoduleid, true);