Commit e90ff142 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge "Rewrite slow upgrades (mysql) (bug #817796)"

parents 0f1d411f d41717dd
......@@ -308,25 +308,17 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
);
}
else {
$folders = get_records_select_array(
'artefact',
'artefacttype = ? AND title = ? AND description = ?',
array('folder', $imagesdir, $imagesdirdesc),
'owner ASC'
execute_sql("
UPDATE {artefact}, (
SELECT owner, MAX(id) AS folderid
FROM {artefact}
WHERE artefacttype = 'folder' AND title = ? AND description = ?
GROUP BY owner
) f
SET parent = f.folderid, description = ?
WHERE artefacttype = 'profileicon' AND {artefact}.owner = f.owner",
array($imagesdir, $imagesdirdesc, $profileicondesc)
);
if ($folders) {
$lastowner = null;
foreach ($folders as $f) {
if ($f->owner != $lastowner) {
execute_sql("
UPDATE {artefact} SET parent = ?, description = ?
WHERE owner = ? AND artefacttype = 'profileicon'",
array($f->id, $profileicondesc, $f->owner)
);
}
$lastowner = $f->owner;
}
}
}
}
......
......@@ -2519,30 +2519,22 @@ function xmldb_core_upgrade($oldversion=0) {
);
}
else {
// Set group quotas for existing groups
$sql = 'SELECT g.id AS id, SUM(aff.size) AS quotaused
FROM {group} g
LEFT OUTER JOIN {artefact} a ON (g.id = a.group)
LEFT OUTER JOIN {artefact_file_files} aff ON (a.id = aff.artefact)
WHERE g.quota IS NULL AND g.quotaused = 0
GROUP BY g.id';
if ($records = get_records_sql_array($sql, array())) {
$default = 52428800; // 50MB
foreach ($records as $record) {
if (empty($record->quotaused)) {
$record->quotaused = 0;
}
// Set quota as 50MB for current usage below 50MB, and current + 50MB for usage above 50MB
execute_sql(
'UPDATE {group} SET quotaused = ?, quota = ? WHERE id = ?',
array(
$record->quotaused,
$record->quotaused < $default ? $default : $record->quotaused + $default,
$record->id
)
);
}
}
execute_sql("
UPDATE {group}, (
SELECT g.id AS id, COALESCE(gf.quotaused, 0) AS quotaused
FROM {group} g
LEFT OUTER JOIN (
SELECT a.group, SUM(aff.size) AS quotaused
FROM {artefact} a JOIN {artefact_file_files} aff ON a.id = aff.artefact
WHERE NOT a.group IS NULL
GROUP BY a.group
) gf ON gf.group = g.id
WHERE g.quota IS NULL AND g.quotaused = 0 AND g.deleted = 0
) f
SET quota = CASE WHEN f.quotaused < 52428800 THEN 52428800 ELSE f.quotaused + 52428800 END,
{group}.quotaused = f.quotaused
WHERE {group}.id = f.id"
);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment