bdaloukas / moodle-mod_game

moodle-mod_game
GNU General Public License v3.0
15 stars 40 forks source link

Big performance bug on Moodle 4+ #63

Closed marxjohnson closed 8 months ago

marxjohnson commented 8 months ago

We have found a bug in the millionaire game causing major performance issues on a Moodle 4.1 site. millionaire/play.php contains the following:

 $select2 = '';
        if (game_get_moodle_version() >= '04.00') {
            $table .= ",{$CFG->prefix}question_bank_entries qbe,{$CFG->prefix}question_versions qv ";
            $select2 = 'qbe.id=qv.questionbankentryid AND q.id=qv.questionid AND qbe.questioncategoryid='.$game->questioncategoryid;
            if ($game->subcategories) {
                $cats = question_categorylist( $game->questioncategoryid);
                if (count( $cats) > 0) {
                    $select2 = ' qbe.questioncategoryid in ('.implode( ',', $cats).')';
                }
            }
        }

If there are subcategories, $select2 is being overwritten, resulting in a query like the following:

SELECT COUNT(*) 
FROM mdl_question q, mdl_qtype_multichoice_options qmo,mdl_question_bank_entries qbe,mdl_question_versions qv  
WHERE  qtype='multichoice' AND qmo.single=1 AND qmo.questionid=q.id AND  qbe.questioncategoryid in (148967, ...);

This is joining mdl_question_bank_entries and mdl_question_versions but with no join condition so all records will be joined.

bdaloukas commented 8 months ago

Version 2023110103 fixes the above problem.