Commit 8148f07c authored by Robert Lyon's avatar Robert Lyon

Bug 1515053: adjusting OR joins to be UNION for artefactchooser

To allow for better performance. Have taken what a user contributed
and tried to make it even more efficient still.

behatnotneeded - existing tests should take care of this

Change-Id: I91ff4e0b5e3e4e22ee437cce5e3da33bace1e736
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 31256ffb
......@@ -3401,21 +3401,22 @@ class View {
safe_require('artefact', 'file');
$public = (int) ArtefactTypeFolder::admin_public_folder_id();
$select = '(
a.owner = ?
OR a.id IN (
$select = ' a.id IN (
SELECT id
FROM {artefact}
WHERE owner = ?
UNION
SELECT id
FROM {artefact}
WHERE (path = ? OR path LIKE ?) AND institution = \'mahara\'
)
OR a.id IN (
UNION
SELECT aar.artefact
FROM {group_member} m
JOIN {artefact} aa ON m.group = aa.group
JOIN {artefact_access_role} aar ON aar.role = m.role AND aar.artefact = aa.id
WHERE m.member = ? AND aar.can_republish = 1
)
OR a.id IN (SELECT artefact FROM {artefact_access_usr} WHERE usr = ? AND can_republish = 1)';
UNION
SELECT artefact FROM {artefact_access_usr} WHERE usr = ? AND can_republish = 1';
$ph = array($user->get('id'), "/$public", db_like_escape("/$public/") . '%', $user->get('id'), $user->get('id'));
......@@ -3427,12 +3428,13 @@ class View {
if ($institutions) {
$select .= '
OR a.institution IN (' . join(',', array_fill(0, count($institutions), '?')) . ')';
UNION
SELECT id FROM {artefact} WHERE institution IN (' . join(',', array_fill(0, count($institutions), '?')) . ')';
$ph = array_merge($ph, $institutions);
}
$select .= "
)";
)";
}
if (!empty($data['artefacttypes']) && is_array($data['artefacttypes'])) {
......
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