Commit 5e80c61d authored by Ankit Agarwal's avatar Ankit Agarwal Committed by Andrew Nicols
Browse files

MDL-57027 accesslib: Improve perf of sql

parent a6210651
......@@ -3647,11 +3647,15 @@ function get_users_by_capability(context $context, $capability, $fields = '', $s
AND roleid IN (".implode(',', array_keys($prohibited[$cap])) ."))";
} else {
$unions[] = "SELECT ra.userid
FROM {role_assignments} ra
LEFT JOIN {role_assignments} rap ON (rap.userid = ra.userid AND rap.contextid IN ($ctxids) AND rap.roleid IN (".implode(',', array_keys($prohibited[$cap])) ."))
WHERE ra.contextid IN ($ctxids) AND ra.roleid IN (".implode(',', array_keys($needed[$cap])) .")
$unions[] = "SELECT userid
FROM {role_assignments}
WHERE contextid IN ($ctxids) AND roleid IN (".implode(',', array_keys($needed[$cap])) .")
AND userid NOT IN (
SELECT userid
FROM {role_assignments}
WHERE contextid IN ($ctxids)
AND roleid IN (" . implode(',', array_keys($prohibited[$cap])) . ")
Supports Markdown
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