Use DeferredUpdates::addCallableUpdate for generateEventsForRevision

* This diff part of this logic is fairly slow

Change-Id: Id9af5c18f852ba7f1c0d2b53257fe11cb87fc510
This commit is contained in:
Aaron Schulz 2015-05-18 12:58:15 -07:00
parent 6a6e92be57
commit 02f618d620

55
Hooks.php Normal file → Executable file
View file

@ -413,36 +413,41 @@ class EchoHooks {
public static function onArticleSaved( &$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status ) { public static function onArticleSaved( &$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status ) {
global $wgEchoNotifications, $wgRequest; global $wgEchoNotifications, $wgRequest;
if ( $revision ) { if ( !$revision ) {
EchoDiscussionParser::generateEventsForRevision( $revision ); return true;
}
// Handle the case of someone undoing an edit, either through the // Try to do this after the HTTP response
// 'undo' link in the article history or via the API. DeferredUpdates::addCallableUpdate( function() use ( $revision ) {
if ( isset( $wgEchoNotifications['reverted'] ) ) { EchoDiscussionParser::generateEventsForRevision( $revision );
$title = $article->getTitle(); } );
$undidRevId = $wgRequest->getVal( 'wpUndidRevision' );
if ( $undidRevId ) { // Handle the case of someone undoing an edit, either through the
$undidRevision = Revision::newFromId( $undidRevId ); // 'undo' link in the article history or via the API.
if ( $undidRevision && $undidRevision->getTitle()->equals( $title ) ) { if ( isset( $wgEchoNotifications['reverted'] ) ) {
$victimId = $undidRevision->getUser(); $title = $article->getTitle();
if ( $victimId ) { // No notifications for anonymous users $undidRevId = $wgRequest->getVal( 'wpUndidRevision' );
EchoEvent::create( array( if ( $undidRevId ) {
'type' => 'reverted', $undidRevision = Revision::newFromId( $undidRevId );
'title' => $title, if ( $undidRevision && $undidRevision->getTitle()->equals( $title ) ) {
'extra' => array( $victimId = $undidRevision->getUser();
'revid' => $revision->getId(), if ( $victimId ) { // No notifications for anonymous users
'reverted-user-id' => $victimId, EchoEvent::create( array(
'reverted-revision-id' => $undidRevId, 'type' => 'reverted',
'method' => 'undo', 'title' => $title,
), 'extra' => array(
'agent' => $user, 'revid' => $revision->getId(),
) ); 'reverted-user-id' => $victimId,
} 'reverted-revision-id' => $undidRevId,
'method' => 'undo',
),
'agent' => $user,
) );
} }
} }
} }
} }
return true; return true;
} }