berrandonea / moodle-local_problemsection

A local plugin for Moodle, to create an manage special course sections where students work together on a problem.
Other
1 stars 0 forks source link

DB queries in loops #3

Open mudrd8mz opened 7 years ago

mudrd8mz commented 7 years ago

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).