Commit f1dbbaa7 authored by Robert Lyon's avatar Robert Lyon

Bug 1479543: Allowing updating artefact table to run smoother

Mostly for Mysql's benefit but won't hurt postgres to do it this way
as well

Change-Id: Icada6c3945db15279d93c30973eaad7bc2507b13
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 4d676a35
......@@ -3272,7 +3272,23 @@ function xmldb_core_upgrade($oldversion=0) {
// Fill the new field with path data.
// 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");
if (get_config('searchplugin') == 'elasticsearch') {
log_debug('Dropping elasticsearch artefact triggers');
require_once(get_config('docroot') . 'search/elasticsearch/lib.php');
ElasticsearchIndexing::drop_triggers('artefact');
}
$count = 0;
$limit = 1000;
$limitsmall = 200;
$total = count_records_select('artefact', 'path IS NULL AND parent IS NULL');
for ($i = 0; $i <= $total; $i += $limitsmall) {
execute_sql("UPDATE {artefact} SET path = CONCAT('/', id) WHERE path IS NULL AND parent IS NULL LIMIT " . $limitsmall);
$count += $limitsmall;
if (($count % $limit) == 0 || $count == $total) {
log_debug("$count/$total");
set_time_limit(30);
}
}
$newcount = count_records_select('artefact', 'path IS NULL');
if ($newcount) {
$childlevel = 0;
......@@ -3309,6 +3325,10 @@ function xmldb_core_upgrade($oldversion=0) {
} while ($newcount > 0 && $newcount < $lastcount);
log_debug("Done filling in child artefact paths");
}
if (get_config('searchplugin') == 'elasticsearch') {
log_debug("Add triggers back in");
ElasticsearchIndexing::create_triggers('artefact');
}
}
// 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