]> git.mjollnir.org Git - moodle.git/commitdiff
mod/chat:chat_cron() delete stale chat messages with a single query, fast, and portab...
authormartinlanghoff <martinlanghoff>
Tue, 8 Jan 2008 20:58:24 +0000 (20:58 +0000)
committermartinlanghoff <martinlanghoff>
Tue, 8 Jan 2008 20:58:24 +0000 (20:58 +0000)
mod/chat/lib.php

index 03b570b40231cb97584efe764ed4309f9b0d1193..87ecc56066e852c755a4074b571cf2c0d0f3441d 100644 (file)
@@ -204,14 +204,15 @@ function chat_cron () {
 
     chat_delete_old_users();
 
-    /// Delete old messages
-    $keepdays = "SELECT c.keepdays
-                   FROM {$CFG->prefix}chat c
-                  WHERE c.id = {$CFG->prefix}chat_messages.chatid AND c.keepdays > 0";
+    /// Delete old messages with a
+    /// single SQL query.
+    $subselect = "SELECT c.keepdays
+                    FROM {$CFG->prefix}chat c
+                   WHERE c.id = {$CFG->prefix}chat_messages.chatid";
 
-    $sql = "DELETE 
+    $sql = "DELETE
               FROM {$CFG->prefix}chat_messages
-             WHERE timestamp < ( ".time()." - COALESCE(($keepdays), 999999) * 24 * 3600)";
+             WHERE ($subselect) > 0 AND timestamp < ( ".time()." -($subselect) * 24 * 3600)"; 
 
     execute_sql($sql, false);