[MediaWiki-commits] [Gerrit] Revert "Defer onPersonalUrls() DB writes to post-send" - change (mediawiki...Echo)

2016-03-08 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Revert "Defer onPersonalUrls() DB writes to post-send"
..


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

Causes fatals in production for some reason.

This reverts commit 93387806c2674bb678d970a7748f9c225150830b.

Bug: T129299
Change-Id: Ie90aa493e2940fae9d6f380b95f87a4cc7e04622
(cherry picked from commit e372f3ce6f3b7be3bf6b926feb1c93b55ef6c72e)
---
M Hooks.php
M includes/mapper/TargetPageMapper.php
M includes/model/TargetPage.php
3 files changed, 13 insertions(+), 51 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  MaxSem: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Hooks.php b/Hooks.php
index 7d51ae3..b326795 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -724,40 +724,24 @@
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();
diff --git a/includes/mapper/TargetPageMapper.php 
b/includes/mapper/TargetPageMapper.php
index 7cdfde9..f34803a 100644
--- a/includes/mapper/TargetPageMapper.php
+++ b/includes/mapper/TargetPageMapper.php
@@ -28,15 +28,13 @@
$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();
diff --git a/includes/model/TargetPage.php b/includes/model/TargetPage.php
index c678947..dbdc414 100644
--- a/includes/model/TargetPage.php
+++ 

[MediaWiki-commits] [Gerrit] Revert "Defer onPersonalUrls() DB writes to post-send" - change (mediawiki...Echo)

2016-03-08 Thread Catrope (Code Review)
Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/276062

Change subject: Revert "Defer onPersonalUrls() DB writes to post-send"
..

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

Causes fatals in production for some reason.

This reverts commit 93387806c2674bb678d970a7748f9c225150830b.

Bug: T129299
Change-Id: Ie90aa493e2940fae9d6f380b95f87a4cc7e04622
(cherry picked from commit e372f3ce6f3b7be3bf6b926feb1c93b55ef6c72e)
---
M Hooks.php
M includes/mapper/TargetPageMapper.php
M includes/model/TargetPage.php
3 files changed, 13 insertions(+), 51 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/62/276062/1

diff --git a/Hooks.php b/Hooks.php
index 7d51ae3..b326795 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -724,40 +724,24 @@
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();
diff --git a/includes/mapper/TargetPageMapper.php 
b/includes/mapper/TargetPageMapper.php
index 7cdfde9..f34803a 100644
--- a/includes/mapper/TargetPageMapper.php
+++ b/includes/mapper/TargetPageMapper.php
@@ -28,15 +28,13 @@
$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();
diff --git a/includes/model/TargetPage.php b/includes/model/TargetPage.php
index c678947..dbdc414 100644
--- 

[MediaWiki-commits] [Gerrit] Revert "Defer onPersonalUrls() DB writes to post-send" - change (mediawiki...Echo)

2016-03-08 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Revert "Defer onPersonalUrls() DB writes to post-send"
..


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

Causes fatals in production for some reason.

This reverts commit 93387806c2674bb678d970a7748f9c225150830b.

Bug: T129299
Change-Id: Ie90aa493e2940fae9d6f380b95f87a4cc7e04622
---
M Hooks.php
M includes/mapper/TargetPageMapper.php
M includes/model/TargetPage.php
3 files changed, 13 insertions(+), 51 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Hooks.php b/Hooks.php
index 7d51ae3..b326795 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -724,40 +724,24 @@
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();
diff --git a/includes/mapper/TargetPageMapper.php 
b/includes/mapper/TargetPageMapper.php
index 7cdfde9..f34803a 100644
--- a/includes/mapper/TargetPageMapper.php
+++ b/includes/mapper/TargetPageMapper.php
@@ -28,15 +28,13 @@
$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();
diff --git a/includes/model/TargetPage.php b/includes/model/TargetPage.php
index d62437a..1d237d7 100644
--- a/includes/model/TargetPage.php
+++ b/includes/model/TargetPage.php
@@ -33,11 +33,6 @@
protected $eventId;
 
/**
-* @var 

[MediaWiki-commits] [Gerrit] Revert "Defer onPersonalUrls() DB writes to post-send" - change (mediawiki...Echo)

2016-03-08 Thread Catrope (Code Review)
Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/276053

Change subject: Revert "Defer onPersonalUrls() DB writes to post-send"
..

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

This reverts commit 93387806c2674bb678d970a7748f9c225150830b.

Change-Id: Ie90aa493e2940fae9d6f380b95f87a4cc7e04622
---
M Hooks.php
M includes/mapper/TargetPageMapper.php
M includes/model/TargetPage.php
3 files changed, 13 insertions(+), 51 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/53/276053/1

diff --git a/Hooks.php b/Hooks.php
index 7d51ae3..b326795 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -724,40 +724,24 @@
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();
diff --git a/includes/mapper/TargetPageMapper.php 
b/includes/mapper/TargetPageMapper.php
index 7cdfde9..f34803a 100644
--- a/includes/mapper/TargetPageMapper.php
+++ b/includes/mapper/TargetPageMapper.php
@@ -28,15 +28,13 @@
$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();
diff --git a/includes/model/TargetPage.php b/includes/model/TargetPage.php
index d62437a..1d237d7 100644
--- a/includes/model/TargetPage.php
+++ b/includes/model/TargetPage.php
@@ -33,11 +33,6 @@
protected $eventId;
 
/**
-* @var string
-