]> git.mjollnir.org Git - moodle.git/commitdiff
More efficient chat listings (less database calling)
authormoodler <moodler>
Tue, 18 Apr 2006 07:14:21 +0000 (07:14 +0000)
committermoodler <moodler>
Tue, 18 Apr 2006 07:14:21 +0000 (07:14 +0000)
mod/chat/lib.php
mod/chat/report.php

index 67e9edafadec868bb6d6c3a5d5d4865626d92a4e..f2eb4abea619d261cba61da05e15a1982691fb6d 100644 (file)
@@ -603,11 +603,16 @@ function chat_format_message($message, $courseid, $currentuser, $chat_lastrow=NU
 /// formats it appropriately into text and html, then
 /// returns the formatted data.
 
-    if (!$user = get_record("user", "id", $message->userid)) {
-        return "Error finding user id = $message->userid";
+    static $users;     // Cache user lookups
+
+    if (isset($users[$message->userid])) {
+        $user = $users[$message->userid];
+    } else if ($user = get_record('user', 'id', $message->userid, '','','','','id,picture,firstname,lastname')) {
+        $users[$message->userid] = $user;
+    } else {
+        return NULL;
     }
     return chat_format_message_manually($message, $courseid, $user, $currentuser, $chat_lastrow);
-
 }
 
 if (!function_exists('ob_get_clean')) {
index 720bf3ac9764c69093e17250293f7988337b8775..98aab321656493f78056ab8aa2ae741f3e080bda 100644 (file)
@@ -79,7 +79,9 @@
             print_simple_box_start('center');
             foreach ($messages as $message) {  // We are walking FORWARDS through messages
                 $formatmessage = chat_format_message($message, $course->id, $USER);
-                echo $formatmessage->html;
+                if (isset($formatmessage->html)) {
+                    echo $formatmessage->html;
+                }
             }
             print_simple_box_end('center');
         }