Commit 3fc71a29 authored by Aaron Wells's avatar Aaron Wells Committed by Son Nguyen

Performance improvements for the code that fills in artefact.path

Bug 1400524: On a large site, the database queries to retrieve
all records from the artefact table can take too long to execute
and cause the PHP script to time out.

This optimization attempts to fix that by separately handling
the simpler case of parentless artefacts, and by removing
a redundant "select * from artefact"

Change-Id: Iddcfea3161fbfe804ec808119fe771757e7cdd5e
parent a73a2a99
......@@ -3270,17 +3270,31 @@ function xmldb_core_upgrade($oldversion=0) {
add_field($table, $field);
// Fill the new field with path data.
$artefacts = get_records_array('artefact', '', '', '', 'id, parent');
$artefact_relations = get_records_menu('artefact', '', '', '', 'id, parent');
if ($artefacts && $artefact_relations) {
foreach ($artefacts as $artefact) {
$path = '/' . implode('/', artefact_get_lineage($artefact_relations, $artefact->id));
// Set all artefacts to the path they'd have if they have no parent.
log_debug('Filling in parent artefact paths');
execute_sql("UPDATE {artefact} SET path = '/' || id WHERE parent IS NULL");
log_debug('Filling in child artefact paths');
set_time_limit(300);
$artefacts = get_records_select_menu('artefact', 'parent IS NOT NULL', null, '', 'id, parent');
set_time_limit(30);
if ($artefacts) {
$total = count($artefacts);
$done = 0;
foreach ($artefacts as $artefactid => $parent) {
$path = '/' . implode('/', artefact_get_lineage($artefacts, $artefactid));
$todb = new stdClass();
$todb->id = $artefact->id;
$todb->id = $artefactid;
$todb->path = $path;
update_record('artefact', $todb);
$done++;
if ($done % 10000 == 0) {
log_debug("Filling in child artefact paths: {$done}/{$total}");
set_time_limit(30);
}
}
log_debug("Filling in child artefact paths: {$done}/{$total}");
}
set_time_limit(300);
}
// Make objectionable independent of view_access page.
......
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