General developer forum

Searching for bug: exponential growth of table, mdl_question. Currently examining the classes restore_controller and backup_controller

 
Picture of Bo Pierce
Searching for bug: exponential growth of table, mdl_question. Currently examining the classes restore_controller and backup_controller
 
Hello,

I am currently looking for the cause of issue MDL-63260.
To do this, I am examining the two classes, restore_controller and backup_controller.
/backup/controller/_____.class.php
The symptoms of this bug are described below.

My request
If you know of other components which I should investigate, please point me toward them.

Tracing the source
Selecting "Duplicate" on a quiz activates /course/mod.php,
which passes a course module to duplicate_module() of lib.php

lib.php then uses the course module as an argument for
  - new backup_controller()
  - new restore_controller()
  - $DB->setfield()

So far, I have not found any loops.

Current assumption
The problem is NOT caused by DB->set_field(), otherwise users would complain of exponential growth on many other tables.

Symptom summary
The symptom appears in the table, mdl_question.
When a quiz is duplicated multiple times,
each question in the quiz is appended to the table a number of times equal to 2^(n-1) , where n equals the number of duplicates created.

For example, a Moodle installation with only 1 quiz and 1 question will generate the following table after the quiz has been duplicated 4 times.

A screenshot of output from MySQL featureing 2 columns and 16 rows. The data fields for these columns are "id," and "parent." the values are integers. id is numbered 16 through 30. Parent featurest he same values, with the exception of 16, which is, instead, the number zero.

16 rows = (1 original quiz) + 2^0 + 2^1 + 2^2 + 2^3
        = (1 original quiz) + 4 duplicates

          (the ID of 16 in my example is irrelevant)

More details about the symptom are beautifully described here: MDL-63260
 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Searching for bug: exponential growth of table, mdl_question. Currently examining the classes restore_controller and backup_controller
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

The cause is clear, and already linked in the tracker. This is a 'regression' cauased by MDL-45851.

In fact, the MDL-45851 fix was right and necessary, it is just that it did not go far enough, and I have not yet thought about the best approach to solve it. Two possibilities:

  1. MDL-45851 change retore to duplicated all random questions, rather than ever risk reusing them. A hard but possibly more correct fix would be to change that logic to only duplicate questions if they are used.
  2. The alternative is to fix this somewhere other than in the backup/restore code. E.g. it would be easier, and would solve other problems too, to have a scheduled task to automatically delete random questions that are no longer used anywhere.


 
Average of ratings: -
Picture of Bo Pierce
Re: Searching for bug: exponential growth of table, mdl_question. Currently examining the classes restore_controller and backup_controller
 

Thank you for clearing up my confusion about the regression.

 
Average of ratings: -
Picture of Bo Pierce
Re: Searching for bug: exponential growth of table, mdl_question. Currently examining the classes restore_controller and backup_controller
 
I have tested my solution by the instructions of MDL-63260.
Any feedback is appreciated.

 
Average of ratings: -