Matthias Mullie has uploaded a new change for review.

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

Change subject: Let EchoUserNotificationGateway return accurate notification 
count
......................................................................

Let EchoUserNotificationGateway return accurate notification count

Query looks pretty much the same (EXPLAIN is identical) and both use
echo_notification_user_base_read_timestamp_timestamp index.
Since there is no performance reason, why not return the accurate
count here & cap it later, where we want it to be capped.

Change-Id: Id460fd7f46e397d22da49283b30fd12a6bbb0c9f
---
M includes/NotifUser.php
M includes/gateway/UserNotificationGateway.php
2 files changed, 10 insertions(+), 12 deletions(-)


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

diff --git a/includes/NotifUser.php b/includes/NotifUser.php
index cd39428..95f072b 100644
--- a/includes/NotifUser.php
+++ b/includes/NotifUser.php
@@ -218,10 +218,11 @@
                        $eventTypesToLoad = 
$attributeManager->getUserEnabledEventsbySections( $this->mUser, 'web', array( 
$section ) );
                }
 
-               $count = $this->userNotifGateway->getNotificationCount( 
$dbSource, $eventTypesToLoad );
+               $count = (int) $this->userNotifGateway->getNotificationCount( 
$dbSource, $eventTypesToLoad );
+               $count = min( $count, MWEchoNotifUser::MAX_NOTIFICATION_COUNT + 
1 );
                $this->cache->set( $memcKey, $count, 86400 );
 
-               return (int)$count;
+               return $count;
        }
 
        /**
diff --git a/includes/gateway/UserNotificationGateway.php 
b/includes/gateway/UserNotificationGateway.php
index 052be82..eeadbdb 100644
--- a/includes/gateway/UserNotificationGateway.php
+++ b/includes/gateway/UserNotificationGateway.php
@@ -78,8 +78,8 @@
 
        /**
         * Get notification count for the types specified
-        * @param int use master or slave storage to pull count
-        * @param array event types to retrieve
+        * @param int $dbSource use master or slave storage to pull count
+        * @param array $eventTypesToLoad event types to retrieve
         * @return int
         */
        public function getNotificationCount( $dbSource, array 
$eventTypesToLoad = array() ) {
@@ -93,12 +93,12 @@
                }
 
                $db = $this->dbFactory->getEchoDb( $dbSource );
-               $res = $db->select(
+               $row = $db->selectRow(
                        array(
                                self::$notificationTable,
                                self::$eventTable
                        ),
-                       array( 'notification_event' ),
+                       array( 'count' => 'COUNT(*)' ),
                        array(
                                'notification_user' => $this->user->getId(),
                                'notification_bundle_base' => 1,
@@ -106,16 +106,13 @@
                                'event_type' => $eventTypesToLoad,
                        ),
                        __METHOD__,
-                       array( 'LIMIT' => 
MWEchoNotifUser::MAX_NOTIFICATION_COUNT + 1 ),
+                       array(),
                        array(
                                'echo_event' => array( 'LEFT JOIN', 
'notification_event=event_id' ),
                        )
                );
-               if ( $res ) {
-                       return $db->numRows( $res );
-               } else {
-                       return 0;
-               }
+
+               return $row ? (int) $row->count : 0;
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/277242
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id460fd7f46e397d22da49283b30fd12a6bbb0c9f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to