diff --git a/includes/NotifUser.php b/includes/NotifUser.php index e1c0c50f5..889aa79c3 100644 --- a/includes/NotifUser.php +++ b/includes/NotifUser.php @@ -177,27 +177,30 @@ class MWEchoNotifUser { /** * Get message count for this user. * - * @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true) - * @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA) * @return int */ - public function getMessageCount( $cached = true, $dbSource = DB_REPLICA ) { - return $this->getNotificationCount( $cached, $dbSource, EchoAttributeManager::MESSAGE ); + public function getMessageCount() { + return $this->getNotificationCount( EchoAttributeManager::MESSAGE ); } /** * Get alert count for this user. * - * @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true) - * @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA) * @return int */ - public function getAlertCount( $cached = true, $dbSource = DB_REPLICA ) { - return $this->getNotificationCount( $cached, $dbSource, EchoAttributeManager::ALERT ); + public function getAlertCount() { + return $this->getNotificationCount( EchoAttributeManager::ALERT ); } - public function getLocalNotificationCount( $cached = true, $dbSource = DB_REPLICA, $section = EchoAttributeManager::ALL ) { - return $this->getNotificationCount( $cached, $dbSource, $section, false ); + /** + * Get the number of unread local notifications in a given section. This does not include + * foreign notifications, even if the user has cross-wiki notifications enabled. + * + * @param string $section Notification section + * @return int + */ + public function getLocalNotificationCount( $section = EchoAttributeManager::ALL ) { + return $this->getNotificationCount( $section, false ); } /** @@ -206,13 +209,11 @@ class MWEchoNotifUser { * * If $wgEchoCrossWikiNotifications is disabled, the $global parameter is ignored. * - * @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true) - * @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA) * @param string $section Notification section * @param bool|string $global Whether to include foreign notifications. If set to 'preference', uses the user's preference. * @return int */ - public function getNotificationCount( $cached = true, $dbSource = DB_REPLICA, $section = EchoAttributeManager::ALL, $global = 'preference' ) { + public function getNotificationCount( $section = EchoAttributeManager::ALL, $global = 'preference' ) { if ( $this->mUser->isAnon() ) { return 0; } @@ -235,23 +236,19 @@ class MWEchoNotifUser { /** * Get the timestamp of the latest unread alert * - * @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true) - * @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA) * @return bool|MWTimestamp Timestamp of latest unread alert, or false if there are no unread alerts. */ - public function getLastUnreadAlertTime( $cached = true, $dbSource = DB_REPLICA ) { - return $this->getLastUnreadNotificationTime( $cached, $dbSource, EchoAttributeManager::ALERT ); + public function getLastUnreadAlertTime() { + return $this->getLastUnreadNotificationTime( EchoAttributeManager::ALERT ); } /** * Get the timestamp of the latest unread message * - * @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true) - * @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA) * @return bool|MWTimestamp */ - public function getLastUnreadMessageTime( $cached = true, $dbSource = DB_REPLICA ) { - return $this->getLastUnreadNotificationTime( $cached, $dbSource, EchoAttributeManager::MESSAGE ); + public function getLastUnreadMessageTime() { + return $this->getLastUnreadNotificationTime( EchoAttributeManager::MESSAGE ); } /** @@ -259,13 +256,11 @@ class MWEchoNotifUser { * * If $wgEchoCrossWikiNotifications is disabled, the $global parameter is ignored. * - * @param bool $cached Set to false to bypass the cache. (Optional. Defaults to true) - * @param int $dbSource Use master or slave database to pull count (Optional. Defaults to DB_REPLICA) * @param string $section Notification section * @param bool|string $global Whether to include foreign notifications. If set to 'preference', uses the user's preference. * @return bool|MWTimestamp Timestamp of latest unread message, or false if there are no unread messages. */ - public function getLastUnreadNotificationTime( $cached = true, $dbSource = DB_REPLICA, $section = EchoAttributeManager::ALL, $global = 'preference' ) { + public function getLastUnreadNotificationTime( $section = EchoAttributeManager::ALL, $global = 'preference' ) { if ( $this->mUser->isAnon() ) { return false; } diff --git a/includes/api/ApiEchoMarkRead.php b/includes/api/ApiEchoMarkRead.php index 8cd60ece3..d53067c6d 100644 --- a/includes/api/ApiEchoMarkRead.php +++ b/includes/api/ApiEchoMarkRead.php @@ -42,7 +42,7 @@ class ApiEchoMarkRead extends ApiBase { ]; $rawCount = 0; foreach ( EchoAttributeManager::$sections as $section ) { - $rawSectionCount = $notifUser->getNotificationCount( /* $tryCache = */true, DB_REPLICA, $section ); + $rawSectionCount = $notifUser->getNotificationCount( $section ); $result[$section]['rawcount'] = $rawSectionCount; $result[$section]['count'] = EchoNotificationController::formatNotificationCount( $rawSectionCount ); $rawCount += $rawSectionCount; diff --git a/includes/api/ApiEchoNotifications.php b/includes/api/ApiEchoNotifications.php index 09db98acc..1f2b47967 100644 --- a/includes/api/ApiEchoNotifications.php +++ b/includes/api/ApiEchoNotifications.php @@ -297,7 +297,7 @@ class ApiEchoNotifications extends ApiCrossWikiBase { $totalRawCount = 0; foreach ( $sections as $section ) { - $rawCount = $notifUser->getNotificationCount( /* $tryCache = */true, DB_REPLICA, $section, $global ); + $rawCount = $notifUser->getNotificationCount( $section, $global ); if ( $groupBySection ) { $result[$section]['rawcount'] = $rawCount; $result[$section]['count'] = EchoNotificationController::formatNotificationCount( $rawCount ); diff --git a/maintenance/backfillUnreadWikis.php b/maintenance/backfillUnreadWikis.php index fb9d9e73a..432dc0536 100644 --- a/maintenance/backfillUnreadWikis.php +++ b/maintenance/backfillUnreadWikis.php @@ -48,11 +48,11 @@ class BackfillUnreadWikis extends Maintenance { $notifUser = MWEchoNotifUser::newFromUser( $user ); $uw = EchoUnreadWikis::newFromUser( $user ); if ( $uw ) { - $alertCount = $notifUser->getNotificationCount( true, DB_REPLICA, EchoAttributeManager::ALERT, false ); - $alertUnread = $notifUser->getLastUnreadNotificationTime( true, DB_REPLICA, EchoAttributeManager::ALERT, false ); + $alertCount = $notifUser->getNotificationCount( EchoAttributeManager::ALERT, false ); + $alertUnread = $notifUser->getLastUnreadNotificationTime( EchoAttributeManager::ALERT, false ); - $msgCount = $notifUser->getNotificationCount( true, DB_REPLICA, EchoAttributeManager::MESSAGE, false ); - $msgUnread = $notifUser->getLastUnreadNotificationTime( true, DB_REPLICA, EchoAttributeManager::MESSAGE, false ); + $msgCount = $notifUser->getNotificationCount( EchoAttributeManager::MESSAGE, false ); + $msgUnread = $notifUser->getLastUnreadNotificationTime( EchoAttributeManager::MESSAGE, false ); if ( ( $alertCount !== 0 && $alertUnread === false ) || ( $msgCount !== 0 && $msgUnread === false ) ) { // If there are alerts, there should be an alert timestamp (same for messages).