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 ) {
global $wgEchoNotifications, $wgRequest;
if ( $revision ) {
EchoDiscussionParser::generateEventsForRevision( $revision );
if ( !$revision ) {
return true;
}
// Handle the case of someone undoing an edit, either through the
// 'undo' link in the article history or via the API.
if ( isset( $wgEchoNotifications['reverted'] ) ) {
$title = $article->getTitle();
$undidRevId = $wgRequest->getVal( 'wpUndidRevision' );
if ( $undidRevId ) {
$undidRevision = Revision::newFromId( $undidRevId );
if ( $undidRevision && $undidRevision->getTitle()->equals( $title ) ) {
$victimId = $undidRevision->getUser();
if ( $victimId ) { // No notifications for anonymous users
EchoEvent::create( array(
'type' => 'reverted',
'title' => $title,
'extra' => array(
'revid' => $revision->getId(),
'reverted-user-id' => $victimId,
'reverted-revision-id' => $undidRevId,
'method' => 'undo',
),
'agent' => $user,
) );
}
// Try to do this after the HTTP response
DeferredUpdates::addCallableUpdate( function() use ( $revision ) {
EchoDiscussionParser::generateEventsForRevision( $revision );
} );
// Handle the case of someone undoing an edit, either through the
// 'undo' link in the article history or via the API.
if ( isset( $wgEchoNotifications['reverted'] ) ) {
$title = $article->getTitle();
$undidRevId = $wgRequest->getVal( 'wpUndidRevision' );
if ( $undidRevId ) {
$undidRevision = Revision::newFromId( $undidRevId );
if ( $undidRevision && $undidRevision->getTitle()->equals( $title ) ) {
$victimId = $undidRevision->getUser();
if ( $victimId ) { // No notifications for anonymous users
EchoEvent::create( array(
'type' => 'reverted',
'title' => $title,
'extra' => array(
'revid' => $revision->getId(),
'reverted-user-id' => $victimId,
'reverted-revision-id' => $undidRevId,
'method' => 'undo',
),
'agent' => $user,
) );
}
}
}
}
return true;
}