MDL-29803 report/logs - don't retrieve all users uncessarily
authorDan Poltawski <dan.poltawski@luns.net.uk>
Tue, 1 Nov 2011 16:30:24 +0000 (16:30 +0000)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 8 Nov 2011 23:49:36 +0000 (00:49 +0100)
Also remove uncessary retrieval of idnumber

Helps display the main logs page on large sites without running out of
memory

course/report/log/lib.php

index eca683b..06ded6a 100644 (file)
@@ -350,7 +350,12 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today'
     // Get all the possible users
     $users = array();
 
-    $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, u.firstname, u.lastname, u.idnumber', 'lastname ASC, firstname ASC');
+    // Define limitfrom and limitnum for queries below
+    // If $showusers is enabled... don't apply limitfrom and limitnum
+    $limitfrom = empty($showusers) ? 0 : '';
+    $limitnum  = empty($showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : '';
+
+    $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname ASC', $limitfrom, $limitnum);
 
     if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) {
         $showusers = 1;
@@ -552,4 +557,4 @@ function log_page_type_list($pagetype, $parentcontext, $currentcontext) {
         //course-report-log-live not included as theres no blocks on the live log page
     );
     return $array;
-}
\ No newline at end of file
+}