Merge "Revert "Defer onPersonalUrls() DB writes to post-send""

This commit is contained in:
jenkins-bot 2016-03-09 00:11:50 +00:00 committed by Gerrit Code Review
commit acdcb5c895
3 changed files with 13 additions and 51 deletions

View file

@ -734,40 +734,24 @@ class EchoHooks {
return true;
}
// Attempt to mark a notification as read when visiting a page
// @todo should this really be here?
$subtractAlerts = 0;
$subtractMessages = 0;
// Attempt to mark a notification as read when visiting a page,
// ideally this should be deferred to end of request and update
// the notification count accordingly
// @Fixme - Find a better place to put this code
if ( $title->getArticleID() ) {
$mapper = new EchoTargetPageMapper();
$targetPages = $mapper->fetchByUserPageId( $user, $title->getArticleID() );
if ( $targetPages ) {
$eventIds = array();
$attribManager = EchoAttributeManager::newFromGlobalVars();
/* @var EchoTargetPage $targetPage */
foreach ( $targetPages as $id => $targetPage ) {
$section = $attribManager->getNotificationSection(
$targetPage->getEventType()
);
if ( $section === EchoAttributeManager::MESSAGE ) {
$subtractMessages += 1;
} else {
// ALERT
$subtractAlerts += 1;
}
$eventIds[] = $id;
}
DeferredUpdates::addCallableUpdate( function () use ( $user, $eventIds ) {
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser->markRead( $eventIds );
} );
$eventIds = array_keys( $targetPages );
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser->markRead( $eventIds );
}
}
// Add a "My notifications" item to personal URLs
$notifUser = MWEchoNotifUser::newFromUser( $user );
$msgCount = $notifUser->getMessageCount() - $subtractMessages;
$alertCount = $notifUser->getAlertCount() - $subtractAlerts;
$msgCount = $notifUser->getMessageCount();
$alertCount = $notifUser->getAlertCount();
$msgNotificationTimestamp = $notifUser->getLastUnreadMessageTime();
$alertNotificationTimestamp = $notifUser->getLastUnreadAlertTime();

View file

@ -28,15 +28,13 @@ class EchoTargetPageMapper extends EchoAbstractMapper {
$dbr = $this->dbFactory->getEchoDb( DB_SLAVE );
$res = $dbr->select(
array( 'echo_target_page', 'echo_event' ),
array_merge( self::$fields, array( 'event_type' ) ),
array( 'echo_target_page' ),
self::$fields,
array(
'etp_user' => $user->getId(),
'etp_page' => $pageId
),
__METHOD__,
array(),
array( 'echo_event' => array( 'JOIN', 'etp_event=event_id' ) )
__METHOD__
);
if ( $res ) {
$targetPages = array();

View file

@ -32,11 +32,6 @@ class EchoTargetPage extends EchoAbstractEntity {
*/
protected $eventId;
/**
* @var string
*/
protected $eventType;
/**
* Only allow creating instance internally
*/
@ -49,7 +44,7 @@ class EchoTargetPage extends EchoAbstractEntity {
* @param User $user
* @param Title $title
* @param EchoEvent $event
* @return EchoTargetPage|null
* @return TargetPage|null
*/
public static function create( User $user, Title $title, EchoEvent $event ) {
// This only support title with a page_id
@ -60,7 +55,6 @@ class EchoTargetPage extends EchoAbstractEntity {
$obj->user = $user;
$obj->event = $event;
$obj->eventId = $event->getId();
$obj->eventType = $event->getType();
$obj->title = $title;
$obj->pageId = $title->getArticleID();
@ -89,9 +83,6 @@ class EchoTargetPage extends EchoAbstractEntity {
$obj->user = User::newFromId( $row->etp_user );
$obj->pageId = $row->etp_page;
$obj->eventId = $row->etp_event;
if ( isset( $row->event_type ) ) {
$obj->eventType = $row->event_type;
}
return $obj;
}
@ -139,17 +130,6 @@ class EchoTargetPage extends EchoAbstractEntity {
return $this->eventId;
}
/**
* @return string
*/
public function getEventType() {
if ( !$this->eventType ) {
$this->eventType = $this->getEvent()->getType();
}
return $this->eventType;
}
/**
* Convert the properties to a database row
* @return array