appdb/cron cleanup.php

WineHQ wineowner at wine.codeweavers.com
Wed Jul 5 23:39:03 CDT 2006


ChangeSet ID:	26197
CVSROOT:	/opt/cvs-commit
Module name:	appdb
Changes by:	wineowner at winehq.org	2006/07/05 23:39:02

Modified files:
	cron           : cleanup.php 

Log message:
	Chris Morgan <cmorgan at alum.wpi.edu>
	Purge orphaned messages from sessionMessages that are older than 1 day after notifying admins
	of the number of orphaned messages. We currently have
	over 150k messages stuck in this table with the earliest dating back to 2004.
	We need to ensure that this doesn't occur again and that we can detect leaked
	messages as these represent bugs in the appdb code.

Patch: http://cvs.winehq.org/patch.py?id=26197

Old revision  New revision  Changes     Path
 1.26          1.27          +32 -2      appdb/cron/cleanup.php

Index: appdb/cron/cleanup.php
diff -u -p appdb/cron/cleanup.php:1.26 appdb/cron/cleanup.php:1.27
--- appdb/cron/cleanup.php:1.26	6 Jul 2006  4:39: 2 -0000
+++ appdb/cron/cleanup.php	6 Jul 2006  4:39: 2 -0000
@@ -72,7 +72,8 @@ notifyAdminsOfCleanupExecution($usersWar
 /* check to see if there are orphaned versions in the database */
 orphanVersionCheck();
 
-
+/* check to see if we have any orphaned messages stuck in sessionMessages table */
+orphanSessionMessagesCheck();
 
 
 /* Users that are unwarned and inactive since $iMonths */
@@ -149,7 +150,7 @@ function orphanVersionCheck()
     $found_orphans = false;
 
     $sMsg = "Found these orphaned versions in the database with\r\n";
-    $sMSg = "this sql command '".$sQuery."'\r\n";
+    $sMsg.= "this sql command '".$sQuery."'\r\n";
 
     /* don't report anything if no orphans are found */
     if(mysql_num_rows($hResult) == 0)
@@ -167,3 +168,32 @@ function orphanVersionCheck()
     if($sEmail)
         mail_appdb($sEmail, $sSubject, $sMsg);
 }
+
+/* this function checks to see if we have any orphaned session messages */
+/* These orphaned messages are an indication that we've put a message into */
+/* the system without displaying it and it becomes effectively lost forever */
+/* so we'll want to purge them here after reporting how many we have */
+function orphanSessionMessagesCheck()
+{
+    $iSessionMessageDayLimit = 1; /* the number of days a session message must be stuck before being purges */
+
+    /* get a count of the messages older than $iSessionMessageDayLimit */
+    $sQuery = "SELECT count(*) as cnt from sessionMessages where TO_DAYS(NOW()) - TO_DAYS(time) > ?";
+    $hResult = query_parameters($sQuery, $iSessionMessageDayLimit);
+
+    $oRow = mysql_fetch_object($hResult);
+    $iMessages = $oRow->cnt;
+
+    $sMsg = "Found ".$iMessages." that have been orphaned in the sessionMessages table for longer than ".$iSessionMessageDayLimit." days\r\n";
+    $sMsg.= " Purging these messages.\r\n";
+
+    $sSubject = "Messages orphaned in sessionMessages\r\n";
+
+    $sEmail = User::get_notify_email_address_list(null, null); /* get list admins */
+    if($sEmail)
+        mail_appdb($sEmail, $sSubject, $sMsg);
+
+    /* purge the messages older than $iSessionMessageDayLimit */
+    $sQuery = "DELETE from sessionMessages where TO_DAYS(NOW()) - TO_DAYS(time) > ?";
+    $hResult = query_parameters($sQuery, $iSessionMessageDayLimit);
+}



More information about the wine-cvs mailing list