Project: moodle
Issue MDL-42882: Performance improvement to missing root directory upgrade step
In the update process for version 2013051402.10 there is a fix for missing root folder entries. (File: lib/db/upgrade.php line 2216) To find the fileareas where these entries are missing a left join is used. We have some installations with really large files table (more then 600 MB). On these installations the update fails at this point. Here is my attempt to get this work. Maybe it helps other people with the same problem. {code} if ($oldversion < 2013051402.10) { $sql = "SELECT distinct f1.contextid, f1.component, f1.filearea, f1.itemid FROM {files} f1 WHERE f1.component <> 'user' or f1.filearea <> 'draft'"; $rs = $DB->get_recordset_sql($sql); $defaults = array('filepath' => '/', 'filename' => '.', 'userid' => $USER->id, 'filesize' => 0, 'timecreated' => time(), 'timemodified' => time(), 'contenthash' => sha1('')); foreach ($rs as $r) { // Is there a root folder entry for that filearea? $count = $DB->count_records('files', array( 'contextid' => $r->contextid, 'component' => $r->component, 'filearea' => $r->filearea, 'itemid' => $r->itemid, 'filename' => '.', 'filepath' => '/' )); if ($count) { continue; } // There is no root folder entry for that filearea. $pathhash = sha1("/$r->contextid/$r->component/$r->filearea/$r->itemid".'/.'); $DB->insert_record('files', (array)$r + $defaults + array('pathnamehash' => $pathhash)); } $rs->close(); // Main savepoint reached. upgrade_main_savepoint(true, 2013051402.10); } {code}
Story points: 20