From 1cc6f6464eaa6dc712a30286d7d35e05774dbadc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Mon, 1 May 2017 12:06:56 +0000 Subject: [PATCH] Add hook for cleaning up data that depends on purged recentchanges rows Adds RecentChangesPurgeRows hook which gets called in the same transaction where old recentchanges rows are purged, and gets the list of deleted rows. Extensions which store data for joining to recentchanges can use this to purge their own data. Bug: T159753 Change-Id: I03f1d485a1a3004412e0859d9d878b7895c95b40 --- RELEASE-NOTES-1.30 | 2 ++ docs/hooks.txt | 5 +++++ includes/jobqueue/jobs/RecentChangesUpdateJob.php | 11 +++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30 index be21a7d9b2..453368bebb 100644 --- a/RELEASE-NOTES-1.30 +++ b/RELEASE-NOTES-1.30 @@ -35,6 +35,8 @@ production. LanguageConverter variant. This allows English-speaking developers to develop and test LanguageConverter more easily. Pig Latin can be enabled by setting $wgUsePigLatinVariant to true. +* Added RecentChangesPurgeRows hook to allow extensions to purge data that + depends on the recentchanges table. === Languages updated in 1.30 === diff --git a/docs/hooks.txt b/docs/hooks.txt index 8485b024b7..fec7d44d5e 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2716,6 +2716,11 @@ random pages. 'RecentChange_save': Called at the end of RecentChange::save(). &$recentChange: RecentChange object +'RecentChangesPurgeRows': Called when old recentchanges rows are purged, after +deleting those rows but within the same transaction. +$rows: The deleted rows as an array of recentchanges row objects (with up to + $wgUpdateRowsPerQuery items). + 'RedirectSpecialArticleRedirectParams': Lets you alter the set of parameter names such as "oldid" that are preserved when using redirecting special pages such as Special:MyPage and Special:MyTalk. diff --git a/includes/jobqueue/jobs/RecentChangesUpdateJob.php b/includes/jobqueue/jobs/RecentChangesUpdateJob.php index ca57d62340..6f349d4447 100644 --- a/includes/jobqueue/jobs/RecentChangesUpdateJob.php +++ b/includes/jobqueue/jobs/RecentChangesUpdateJob.php @@ -86,14 +86,21 @@ class RecentChangesUpdateJob extends Job { $ticket = $factory->getEmptyTransactionTicket( __METHOD__ ); $cutoff = $dbw->timestamp( time() - $wgRCMaxAge ); do { - $rcIds = $dbw->selectFieldValues( 'recentchanges', - 'rc_id', + $rcIds = []; + $rows = []; + $res = $dbw->select( 'recentchanges', + RecentChange::selectFields(), [ 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ], __METHOD__, [ 'LIMIT' => $wgUpdateRowsPerQuery ] ); + foreach ( $res as $row ) { + $rcIds[] = $row->rc_id; + $rows[] = $row; + } if ( $rcIds ) { $dbw->delete( 'recentchanges', [ 'rc_id' => $rcIds ], __METHOD__ ); + Hooks::run( 'RecentChangesPurgeRows', [ $rows ] ); // There might be more, so try waiting for replica DBs try { $factory->commitAndWaitForReplication( -- 2.20.1