Function local_problemsection_get_studentids() uses DB queries inside a foreach loop. That is generally a very bad pattern from performance perspective. Especially here where you iterate over records in the role_assignments table. There can be potentially thousands of records in big courses and loops like this can easily have significant impact on the site performance.
In this particular case, I would recommend to simply remove the if ($DB->record_exists('user' ... check.
In fact, what you probably really want in this function is to call the Moodle core function get_enrolled_users() (not its second argument $withcapability).
Function
local_problemsection_get_studentids()
uses DB queries inside a foreach loop. That is generally a very bad pattern from performance perspective. Especially here where you iterate over records in the role_assignments table. There can be potentially thousands of records in big courses and loops like this can easily have significant impact on the site performance.In this particular case, I would recommend to simply remove the
if ($DB->record_exists('user' ...
check.In fact, what you probably really want in this function is to call the Moodle core function
get_enrolled_users()
(not its second argument$withcapability
).