Commit e825502d authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Join on artefact table when fetching group artefacts (bug #872631)



The artefact_access_role subselect can return a lot of rows when
artefact_access_role is joined to group_member without also going
through artefact.

Also, the artefact_access_role & artefact_access_usr checks are
moved in to subselects in the where clause, because that appears
to make the query run faster.

Change-Id: Ibba16c8db59213fe4861262a950d628937f5ec13
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent b49a1353
......@@ -2363,8 +2363,9 @@ class View {
SELECT
r.artefact, r.can_view, r.can_edit, m.group
FROM
{artefact_access_role} r
INNER JOIN {group_member} m ON r.role = m.role
{group_member} m
JOIN {artefact} aa ON aa.group = m.group
JOIN {artefact_access_role} r ON aa.id = r.artefact AND r.role = m.role
WHERE
m.group = ?
AND m.member = ?
......@@ -2393,25 +2394,20 @@ class View {
safe_require('artefact', 'file');
$from .= "
LEFT OUTER JOIN {artefact_access_usr} aau ON (a.id = aau.artefact AND aau.usr = ?)
LEFT OUTER JOIN {artefact_parent_cache} apc ON (a.id = apc.artefact AND a.institution = 'mahara' AND apc.parent = ?)
LEFT OUTER JOIN (
SELECT
aar.artefact, aar.can_republish, m.group
FROM
{artefact_access_role} aar
INNER JOIN {group_member} m ON aar.role = m.role
WHERE
m.member = ?
AND aar.can_republish = 1
) ra ON (a.id = ra.artefact AND a.group = ra.group)";
LEFT OUTER JOIN {artefact_parent_cache} apc ON (a.id = apc.artefact AND a.institution = 'mahara' AND apc.parent = ?)";
$select = '(
a.owner = ?
OR ra.can_republish = 1
OR aau.can_republish = 1';
OR a.id IN (
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)';
$ph = array($user->get('id'), (int) ArtefactTypeFolder::admin_public_folder_id(), $user->get('id'), $user->get('id'));
$ph = array((int) ArtefactTypeFolder::admin_public_folder_id(), $user->get('id'), $user->get('id'), $user->get('id'));
$institutions = array_keys($user->get('institutions'));
......
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