Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.9
-
Fix Version/s: 2.0
-
Component/s: Roles / Access
-
Labels:None
-
Difficulty:Difficult
-
Affected Branches:MOODLE_19_STABLE
-
Fixed Branches:MOODLE_20_STABLE
Description
I very often see duplicate ra's in $USER->access. For example (just the first few lines):
Array
(
::::[ra] => Array
:::::::![]()
::::::::::::[/1/154/184] => Array
:::::::::::::::![]()
:::::::::::::::::::::[0] => 5
:::::::::::::::::::::[1] => 5
Duplicate ra's double the work of calculating permissions without changing the result. Sometimes there are more than two duplicates. I recently helped a user debug a problem and there were SEVEN duplicates of two different roles! This is a major efficiency issue.
Martin Langhoff suggested the fix below, but it does not eliminate the problem.
Change the last line of the SQL query in get_user_access_sitewide() and load_subcontext() (both functions in lib/accesslib.php
ORDER BY ctx.depth ASC, ctx.path ASC, ra.roleid ASC
(Added ASC to make the order unambiguous. Different DBs default to
different defaults, so what works in mySQL might break subtly in Oracle.)
Uhm...
it seems that ordering by ctx.depth ASC, ctx.path ASC, ra.roleid ASC solves the problem in get_user_access_sitewide(), because there is code included to prevent duplicates (the $lastseen checker).
But AFAIK load_subcontext() doesn't include such code to prevent duplicates, so the ordering solution won't cause any effect.
So I've added that prevention of duplicates in load_subcontext() and seems to be working here. Patch attached, can you please test it?
Ciao