Add hook for cleaning up data that depends on purged recentchanges rows
authorGergő Tisza <gtisza@wikimedia.org>
Mon, 1 May 2017 12:06:56 +0000 (12:06 +0000)
committerGergő Tisza <tgr.huwiki@gmail.com>
Mon, 10 Jul 2017 14:12:30 +0000 (16:12 +0200)
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
docs/hooks.txt
includes/jobqueue/jobs/RecentChangesUpdateJob.php

index be21a7d..453368b 100644 (file)
@@ -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 ===
 
index 8485b02..fec7d44 100644 (file)
@@ -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.
index ca57d62..6f349d4 100644 (file)
@@ -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(