Commit 8fe741f4 authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review
Browse files

Refactor the function artefact_get_descendants(). Bug 1423761

Using the path column to avoid recursive queries

Change-Id: I51eab6ce248c5f0d199487d85d9a56f8ffa3e001
parent 393e1608
......@@ -1701,26 +1701,30 @@ function artefact_watchlist_notification($artefactids) {
// responding to the event saveartefact
}
function artefact_get_descendants($new) {
$seen = array();
if (!empty($new)) {
$new = array_combine($new, $new);
}
while (!empty($new)) {
$seen = $seen + $new;
$children = get_column_sql('
SELECT id
/**
* Returns the id of descendant artefacts of the given artefacts
* @param array $ids: IDs of ancestral artefacts
* @return array
*/
function artefact_get_descendants(array $ids) {
if (empty($ids)) {
return array();
}
if ($aids = get_column_sql('
SELECT DISTINCT id
FROM {artefact}
WHERE parent IN (' . implode(',', array_map('intval', $new)) . ') AND id NOT IN (' . implode(',', array_map('intval', $seen)) . ')', array());
if ($children) {
$new = array_diff($children, $seen);
$new = array_combine($new, $new);
}
else {
$new = array();
}
WHERE ' . join(' OR ', array_map(
function($id) {
return 'path LIKE ' . db_quote('%/' . db_like_escape($id) . '/%');
}
, $ids)) . '
ORDER BY id'
)) {
return array_merge($ids, array_values($aids));
}
else {
return $ids;
}
return array_values($seen);
}
function artefact_owner_sql($userid=null, $groupid=null, $institution=null) {
......
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