We are on Moodle 3.7.7+ (Build: 20200717). A teacher let us know she was having problems duplicating quizzes, and after investigating, we realized that the number of mdl_question records in our database was growing exponentially, as described in MDL-63260 and MDL-64595.
We had several million unused question records at one point. Our automated nightly backups were starting to fail, and we could not open certain quiz pages like question banks, editing pages, or question exports (well, they would take a long time to load).
Long story short: we've curbed the growth, and we are trying to figure out a way to prevent it from happening again. Some more details below for context, and possible solutions after that.
After reading the tracker issues and related forum threads, we increased the frequency of the random question cleanup task (\qtype_random\task\remove_unused_questions). Thankfully, that task eventually cleaned up questions faster than they were being created, so we are down to a reasonable ~3,000 question records.
I have been testing various scenarios on our development site to identify what triggers the exponential growth, so that we can hopefully stop this from happening just by haphazard actions of teachers. As others have pointed out, it definitely happens when you duplicate a quiz with random questions, and when you restore a course backup that contains quizzes with random questions.
However, I have also triggered the exponential growth when duplicating a quiz that does not contain any random questions. It is in a course with a randomized quiz, so it's not completely unexpected. However, this seemed like a variation that I had not seen reported.
At this point, I want to figure out a way to prevent this exponential growth from happening again. That is, I need to prevent people from duplicating a quiz in a course that contains randomized questions, and prevent people from restoring a course backup that contains randomized questions.
However, there is no capability specifically related to random questions. And it does not seem possible to disable the random question type (I even double-checked on one of the public Moodle demo sites, where there are no instances of the question).
If we remove all random questions from our site, it seems we have the option to uninstall the question type (yourmoodle.com/admin/qtypes.php), but that solution is not ideal for our situation. Others might find it helpful, though.
The best I can think of is to just make some kind of notification for our administrators when the question table gets too large. I am not sure exactly how I'll do that (possibly using the very excellent customsql plugin!), but it shouldn't be too hard to get a count of records in the question table sent to me once a day or so. Of course, if the question table gets too large, such a query might take too long, and possibly never complete, but hopefully I would get so conditioned to seeing the daily report that I would notice when I do not receive it.
Has anyone else figured out a decent way to prevent this exponential growth from triggering again? I'll be sure to post back here if I think of something else.