mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
Use DeferredUpdates::addCallableUpdate for generateEventsForRevision
* This diff part of this logic is fairly slow Change-Id: Id9af5c18f852ba7f1c0d2b53257fe11cb87fc510
This commit is contained in:
parent
6a6e92be57
commit
02f618d620
55
Hooks.php
Normal file → Executable file
55
Hooks.php
Normal file → Executable 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue