From 78c98892d1812ce82e1a228aaabb91bbd773bf3f Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 18 Apr 2006 07:14:21 +0000 Subject: [PATCH] More efficient chat listings (less database calling) --- mod/chat/lib.php | 11 ++++++++--- mod/chat/report.php | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 67e9edafad..f2eb4abea6 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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')) { diff --git a/mod/chat/report.php b/mod/chat/report.php index 720bf3ac97..98aab32165 100644 --- a/mod/chat/report.php +++ b/mod/chat/report.php @@ -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'); } -- 2.39.5