Moved RC purge logic to RecentChange::purgeExpiredChanges().
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 24 Apr 2013 01:31:06 +0000 (18:31 -0700)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 26 Apr 2013 00:09:39 +0000 (00:09 +0000)
* Also deferred the change to onTransactionIdle().

Change-Id: Ife8a06c0ac9230bfe564d17c33f16cb989c8bc24

includes/RecentChange.php
includes/WikiPage.php

index faad391..b5d4a1c 100644 (file)
@@ -825,6 +825,29 @@ class RecentChange {
                return ChangesList::showCharacterDifference( $old, $new );
        }
 
+       /**
+        * Purge expired changes from the recentchanges table
+        * @since 1.22
+        */
+       public static function purgeExpiredChanges() {
+               if ( wfReadOnly() ) {
+                       return;
+               }
+
+               $method = __METHOD__;
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->onTransactionIdle( function() use ( $dbw, $method ) {
+                       global $wgRCMaxAge;
+
+                       $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
+                       $dbw->delete(
+                               'recentchanges',
+                               array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
+                               $method
+                       );
+               } );
+       }
+
        private static function checkIPAddress( $ip ) {
                global $wgRequest;
                if ( $ip ) {
index 39a71ad..c2aad76 100644 (file)
@@ -2080,15 +2080,7 @@ class WikiPage implements Page, IDBAccessObject {
                        if ( 0 == mt_rand( 0, 99 ) ) {
                                // Flush old entries from the `recentchanges` table; we do this on
                                // random requests so as to avoid an increase in writes for no good reason
-                               global $wgRCMaxAge;
-
-                               $dbw = wfGetDB( DB_MASTER );
-                               $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
-                               $dbw->delete(
-                                       'recentchanges',
-                                       array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
-                                       __METHOD__
-                               );
+                               RecentChange::purgeExpiredChanges();
                        }
                }