New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notes on upgrading to 4.2.0 & 4.1.2 #220
Comments
Hi, If this fallback is really correct, then I think it should used in any cases, avoiding using UPDATE ... INSERT even for SGBD that supports it. The data is far less than 1 megabyte (of RAM) in our case. I tried it on a production copy here, the script finishes in less that 3 seconds (because the first queries takes some times too). If the result is correct, then it's seem the whole script provided here became useless at least on large MariaDB baked Moodle instances because the same fix could be directly applied in the data migration functions in the plugin itself and take a few seconds at worth case (and not hours). I put here what I exactly run on my production clone (just commenting out the whole try, and forcing to run the fallback code). I have to add 2 lines at start to make it run with <?php
define('CLI_SCRIPT', true);
require(__DIR__ . '/../../config.php');
require_once($CFG->libdir . '/questionlib.php');
function offlinequiz_fix_question_versions() {
global $DB;
[...]
$sql2 = "INSERT INTO {question_references} (itemid, usingcontextid, component, questionarea, questionbankentryid, version) ($sql LIMIT 10000)";
$thiscount = $DB->count_records('question_references');
$lastcount = -1;
/*
try {
while ($thiscount > $lastcount) {
$DB->execute($sql2);
$lastcount = $thiscount;
$thiscount = $DB->count_records('question_references');
}
} catch(Exception $e) {*/
//Database doesn't support this type of insert, we have to get them out of the database and insert them manually.
while ($records = $DB->get_records_sql($sql, [], 0, 10000)) {
$DB->insert_records('question_references', $records);
}
//}
}
offlinequiz_fix_question_versions(); Could you review what I run and say me if it is safe to do migration this way ? Note : with the UPDATE ... SELECT ... with the database data already fixed, so the SELECT alone returns 0 lines, the UPDATE ... SELECT takes also 30 minutes to successfully end with affected rows == 0. And this is currently ran by the plugin 4.1.2 when pushing the database upgrade web button in the moodle administration interface ... so running the given script here costs at least 30 mins downtime on our side when update the plugin if we don't patch it to not try the UPADTE ... SELECT. |
hi @lposmb, sorry for answering so late. I didn't get a mail for this answer. TLDR: The solution you promoted definitely works. I just don't understand why for some mysql databases it's slower and for others it's faster. |
Because of the way the new Question API works many changes had to be made for the new Offlinequiz versions for Moodle 4. The execution of a repair script is now necessary to fix problems caused by those changes in the Offlinequiz versions 4.0 to 4.1.0. Even if you have never used any of the mentioned plugin versions there could be a lot of missing entries in the database and the execution of the script would be helpful anyway.
Attention:
This script takes some time to execute, for example on our pretty powerful instance with 25,000 Offlinequizzes it took around 10 minutes. On not so powerful servers it might take longer.
Instructions for use:
If you use the same question in more than one group - the version will be the same over all groups. This also applies to changes to the version, it will be carried out automatically in all groups where the question has been added!
Further information for admins
The text was updated successfully, but these errors were encountered: