Skip to content

Commit

Permalink
mod/chat:chat_cron() delete stale chat messages with a single query, …
Browse files Browse the repository at this point in the history
…fast, and portable too! MDL-11674
  • Loading branch information
martinlanghoff committed Jan 8, 2008
1 parent 8432e9b commit bf2de34
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions mod/chat/lib.php
Expand Up @@ -205,13 +205,14 @@ 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";
/// 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);

Expand Down

0 comments on commit bf2de34

Please sign in to comment.