From 97b2a1dfdafb20c428513c0dafdb5b96da2226d3 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 21 May 2015 00:21:03 -0700 Subject: [PATCH] Made RecentChange defer the save() method via DeferredUpdates * Also made it handle calling PatrolLog::record() itself Bug: T100042 Change-Id: I58ef060e02b89a5f9dadc0dbc4edba667932beda --- includes/changes/RecentChange.php | 28 ++++++++++++++++++++++------ includes/page/WikiPage.php | 22 +++++++--------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index aa210e3bcd..7ea677723c 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -517,8 +517,10 @@ class RecentChange { * @param int $patrol * @return RecentChange */ - public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId, - $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0 ) { + public static function notifyEdit( + $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp, + $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0 + ) { $rc = new RecentChange; $rc->mTitle = $title; $rc->mPerformer = $user; @@ -555,7 +557,13 @@ class RecentChange { 'newSize' => $newSize, 'pageStatus' => 'changed' ); - $rc->save(); + + DeferredUpdates::addCallableUpdate( function() use ( $rc ) { + $rc->save(); + if ( $rc->mAttribs['rc_patrolled'] ) { + PatrolLog::record( $rc, true, $rc->getPerformer() ); + } + } ); return $rc; } @@ -576,8 +584,10 @@ class RecentChange { * @param int $patrol * @return RecentChange */ - public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot, - $ip = '', $size = 0, $newId = 0, $patrol = 0 ) { + public static function notifyNew( + $timestamp, &$title, $minor, &$user, $comment, $bot, + $ip = '', $size = 0, $newId = 0, $patrol = 0 + ) { $rc = new RecentChange; $rc->mTitle = $title; $rc->mPerformer = $user; @@ -614,7 +624,13 @@ class RecentChange { 'newSize' => $size, 'pageStatus' => 'created' ); - $rc->save(); + + DeferredUpdates::addCallableUpdate( function() use ( $rc ) { + $rc->save(); + if ( $rc->mAttribs['rc_patrolled'] ) { + PatrolLog::record( $rc, true, $rc->getPerformer() ); + } + } ); return $rc; } diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 71b3b7936f..5e4438ac7a 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -1835,18 +1835,13 @@ class WikiPage implements Page, IDBAccessObject { if ( !( $flags & EDIT_SUPPRESS_RC ) ) { // Mark as patrolled if the user can do so $patrolled = $wgUseRCPatrol && !count( - $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) ); - + $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) ); // Add RC row to the DB - $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary, + RecentChange::notifyEdit( + $now, $this->mTitle, $isminor, $user, $summary, $oldid, $this->getTimestamp(), $bot, '', $oldsize, $newsize, $revisionId, $patrolled ); - - // Log auto-patrolled edits - if ( $patrolled ) { - PatrolLog::record( $rc, true, $user ); - } } $user->incEditCount(); @@ -1937,13 +1932,10 @@ class WikiPage implements Page, IDBAccessObject { $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && !count( $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) ); // Add RC row to the DB - $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot, - '', $newsize, $revisionId, $patrolled ); - - // Log auto-patrolled edits - if ( $patrolled ) { - PatrolLog::record( $rc, true, $user ); - } + RecentChange::notifyNew( + $now, $this->mTitle, $isminor, $user, $summary, $bot, + '', $newsize, $revisionId, $patrolled + ); } $user->incEditCount(); -- 2.20.1