You are here

function notifications_event_clean in Notifications 6.3

Same name and namespace in other branches
  1. 6.2 notifications.cron.inc \notifications_event_clean()

Clean up event table

Parameters

$update: Update event counter

2 calls to notifications_event_clean()
notifications_process_prepare in ./notifications.cron.inc
Prepare subscriptions queue
notifications_queue_clean in ./notifications.module
Clean queue for a user and update event tracker

File

./notifications.cron.inc, line 121

Code

function notifications_event_clean($update = FALSE) {

  // This expiretime will prevent some race condition that occurs when the event is saved but the subs queue not yet populated
  $expiretime = time() - 60;
  if ($update) {

    // Update event counter, which keeps the number of notifications pending for each event
    db_query("UPDATE {notifications_event} e SET counter = (SELECT COUNT(*) FROM {notifications_queue} q WHERE q.eid = e.eid ) WHERE e.created < %d", $expiretime);
  }
  db_query("DELETE FROM {notifications_event} WHERE counter = 0 AND created < %d", $expiretime);

  // Delete events with no pending notifications. As events are created sequentially, we use this fact to speed up the query
  db_query("DELETE FROM {notifications_event} WHERE created < %d AND eid < (SELECT MIN(eid) FROM {notifications_queue})", $expiretime);
}