Commit 617691b6 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Do fewer queries when getting artefact children

parent 08cbaf59
...@@ -893,16 +893,22 @@ function artefact_watchlist_notification($artefactid) { ...@@ -893,16 +893,22 @@ function artefact_watchlist_notification($artefactid) {
function artefact_get_descendants($new) { function artefact_get_descendants($new) {
$seen = array(); $seen = array();
while ($n = array_shift($new)) { $new = array_combine($new, $new);
$seen[] = $n; while (!empty($new)) {
$children = get_column_sql('SELECT id FROM {artefact} WHERE parent = ? AND id NOT IN (' . implode(',', $seen) . ')', array($n)); $seen = $seen + $new;
$children = get_column_sql('
SELECT id
FROM {artefact}
WHERE parent IN (' . implode(',', $new) . ') AND id NOT IN (' . implode(',', $seen) . ')', array());
if ($children) { if ($children) {
foreach ($children as $c) { $new = array_diff($children, $seen);
$new[] = $c; $new = array_combine($new, $new);
} }
else {
$new = array();
} }
} }
return $seen; return array_values($seen);
} }
?> ?>
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