More efficient chat listings (less database calling)

This commit is contained in:
moodler
2006-04-18 07:14:21 +00:00
parent 2b9fd72cc3
commit 78c98892d1
2 changed files with 11 additions and 4 deletions
+8 -3
View 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')) {
+3 -1
View 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');
}