From 651ffd355d804b126caf70b5adc04fe7c049f74b Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 23 Apr 2013 18:31:06 -0700 Subject: [PATCH] Moved RC purge logic to RecentChange::purgeExpiredChanges(). * Also deferred the change to onTransactionIdle(). Change-Id: Ife8a06c0ac9230bfe564d17c33f16cb989c8bc24 --- includes/RecentChange.php | 23 +++++++++++++++++++++++ includes/WikiPage.php | 10 +--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/includes/RecentChange.php b/includes/RecentChange.php index faad391044..b5d4a1c531 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -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 ) { diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 39a71ad143..c2aad7687c 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -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(); } } -- 2.20.1