Commit 04da7eb3 authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents 6e5c63c9 d6217fed
......@@ -250,6 +250,13 @@ abstract class ArtefactType {
$this->commit();
}
if (!empty($this->parentdirty)) {
if (!empty($this->parent) && !record_exists('artefact_parent_cache', 'aretfact', $this->id)) {
$apc = new StdClass;
$apc->artefact = $this->id;
$apc->parent = $this->parent;
$apc->dirty = 1; // set this so the cronjob will pick it up and go set all the other parents.
insert_record('artefact_parent_cache', $apc);
}
set_field_select('artefact_parent_cache', 'dirty', 1,
'artefact = ? OR parent = ?', array($this->id, $this->id));
}
......
......@@ -690,5 +690,13 @@
<SENTENCE TEXT="(name, admin, delay) VALUES ('virusrelease', 1, 1)" />
</SENTENCES>
</STATEMENT>
<STATEMENT NAME="insert core cron jobs" TYPE="insert" TABLE="cron">
<SENTENCES>
<SENTENCE TEXT="(callfunction, minute, hour, day, month, dayofweek)
VALUES (rebuild_artefact_parent_cache_dirty, '*', '*', '*', '*', '*')" />
<SENTENCE TEXT="(callfunction, minute, hour, day, month, dayofweek)
VALUES (rebuild_artefact_parent_cache_complete, '*', '4', '*', '*', '*')" />
</SENTENCES>
</STATEMENT>
</STATEMENTS>
</XMLDB>
......@@ -1170,4 +1170,64 @@ function password_validate(Form $form, $values, $user) {
}
}
function rebuild_artefact_parent_cache_dirty() {
// this will give us a list of artefacts, as the first returned column
// is not unqiue, but that's ok, it's what we want.
if (!$dirty = get_records('artefact_parent_cache', 'dirty', 1)) {
return;
}
db_begin();
delete_records('artefact_parent_cache', 'dirty', 1);
foreach ($dirty as $d) {
$parentids = array();
$current = $d->artefact;
while (true) {
if (!$parent = get_record('artefact', 'id', $current)) {
break;
}
if (!$parent->parent) {
break;
}
$parentids[] = $parent->parent;
$current = $parent->parent;
}
foreach ($parentids as $p) {
$apc = new StdClass;
$apc->artefact = $d->artefact;
$apc->parent = $p;
$apc->dirty = 0;
insert_record('artefact_parent_cache', $apc);
}
}
db_commit();
}
function rebuild_artefact_parent_cache_complete() {
db_begin();
delete_records('artefact_parent_cache');
$artefacts = get_records('artefact');
foreach ($artefacts as $a) {
$parentids = array();
$current = $a->id;
while (true) {
if (!$parent = get_record('artefact', 'id', $current)) {
break;
}
if (!$parent->parent) {
break;
}
$parentids[] = $parent->parent;
$current = $parent->parent;
}
foreach ($parentids as $p) {
$apc = new StdClass;
$apc->artefact = $a->id;
$apc->parent = $p;
$apc->dirty = 0;
insert_record('artefact_parent_cache', $apc);
}
}
db_commit();
}
?>
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