mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-38314 repository: Improving performance of upgrade script
This commit is contained in:
parent
65ef774544
commit
0193dd1c32
@ -2193,12 +2193,17 @@ function xmldb_main_upgrade($oldversion) {
|
||||
if ($oldversion < 2013062700.01) {
|
||||
|
||||
// Remove orphan repository instances.
|
||||
$sql = 'SELECT contextid FROM {repository_instances} ri
|
||||
WHERE NOT EXISTS (
|
||||
SELECT id FROM {context} c
|
||||
WHERE c.id = ri.contextid)';
|
||||
$ids = $DB->get_fieldset_sql($sql);
|
||||
$DB->delete_records_list('repository_instances', 'contextid', $ids);
|
||||
if ($DB->get_dbfamily() === 'mysql') {
|
||||
$sql = "DELETE {repository_instances} FROM {repository_instances}
|
||||
LEFT JOIN {context} ON {context}.id = {repository_instances}.contextid
|
||||
WHERE {context}.id IS NULL";
|
||||
} else {
|
||||
$sql = "DELETE FROM {repository_instances}
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 'x' FROM {context}
|
||||
WHERE {context}.id = {repository_instances}.contextid)";
|
||||
}
|
||||
$DB->execute($sql);
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2013062700.01);
|
||||
|
Loading…
x
Reference in New Issue
Block a user