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.
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.
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.
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:
Here is a snippet of the relevant part of our code:

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
Try,
course_delete_module($quiz->quizmoduleid, true);
course_delete_module($quiz->quizmoduleid, true);
Thank you, Howard. This fixed the issue. It deletes the quiz in less than a second now. Hats off to you.