-
Improvement
-
Resolution: Fixed
-
Minor
-
3.4
-
MOODLE_34_STABLE
-
MOODLE_34_STABLE
-
MDL-59897-master -
The function get_user_capability_course in accesslib appears to be potentially slow, in that it loads all courses on the system and checks access against each one. For example, say there are 1,000 courses, then if you are checking whether a user has moodle/course:view on a course, the most common situation might be that they do not have it on any course, in which case it seems like a waste to query for 1,000 courses.
Access checks are done with has_capability which is fast so it's not going to be too terrible, but even so.
I think it should be possible to work out a cleverer query for a subset of courses, based on the existing cached access data. I'm going to take a look at this.
The reason for looking at this function is that I've used it to implement an enhancement MDL-53169 which may then be used for global search, so it would be good to ensure performance is not affected. (get_user_capability_course currently only seems to be used in a couple of admin tools so it isn't really performance-critical at the moment.)
Alongside this potential change, I notice there are no unit tests for this function, so I'll make one.