]> git.mjollnir.org Git - moodle.git/commitdiff
user/index: Fetch participants' contexts with the search
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:55:00 +0000 (07:55 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:55:00 +0000 (07:55 +0000)
With this patch, we fetch participants contexts in the main search
query. This cuts 1DBq per participant for the display.

Might fix MDL-11222 'global teacher viewing participants issues' where
we are getting OOM'd with many users.

user/index.php

index 3e8f4e877edf7586734fe328d3bd3bbe8ae5588d..dedea88e0b985f320f04f7a3ccd47e86330167b6 100644 (file)
     } else {
         $selectrole = " ";
     }
-    $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country, u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, u.imagealt, COALESCE(ul.timeaccess, 0) AS lastaccess, r.hidden '; // s.lastaccess
+    $select = 'SELECT u.id, u.username, u.firstname, u.lastname,
+                      u.email, u.city, u.country, u.picture,
+                      u.lang, u.timezone, u.emailstop, u.maildisplay, u.imagealt,
+                      COALESCE(ul.timeaccess, 0) AS lastaccess,
+                      r.hidden,
+                      ctx.id AS ctxid, ctx.path AS ctxpath,
+                      ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel ';
+
     $select .= $course->enrolperiod?', r.timeend ':'';
 
-    $from   = "FROM {$CFG->prefix}user u INNER JOIN
-    {$CFG->prefix}role_assignments r on u.id=r.userid LEFT OUTER JOIN
-    {$CFG->prefix}user_lastaccess ul on (r.userid=ul.userid and ul.courseid = $course->id)";
+    $from   = "FROM {$CFG->prefix}user u
+               JOIN {$CFG->prefix}context ctx
+                 ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.")
+               JOIN {$CFG->prefix}role_assignments r
+                 ON u.id=r.userid
+               LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul
+                 ON (r.userid=ul.userid and ul.courseid = $course->id) ";
 
     $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 ';
 
 
             if ($matchcount > 0) {
                 foreach ($userlist as $user) {
+                    $user = make_context_subobj($user);
                     print_user($user, $course, $bulkoperations);
                 }
 
 
         if (!empty($userlist))  {
             foreach ($userlist as $user) {
+                $user = make_context_subobj($user);
                 if ($user->hidden) {
                 // if the assignment is hidden, display icon
                     $hidden = "<img src=\"{$CFG->pixpath}/t/hide.gif\" alt=\"".get_string('hiddenassign')."\" class=\"hide-show-image\"/>";
                     }
                 }
 
-                $usercontext = get_context_instance(CONTEXT_USER, $user->id);
+                if (!isset($user->context)) {
+                    $usercontext = get_context_instance(CONTEXT_USER, $user->id);
+                } else {
+                    $usercontext = $user->context;
+                }
 
                 if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) ||has_capability('moodle/user:viewdetails', $context))) {
                     $profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.fullname($user).'</a></strong>';