Page MenuHomePhabricator

Cache foreign notification count in memcached
Closed, ResolvedPublic

Description

We cache the notification count (and also timestamp, for both alerts and messages separately) in memcached, but that count only includes local notifications. We don't cache anything in memcached for foreign notifications:

	public function getAlertCount( $cached = true, $dbSource = DB_SLAVE ) {
		$count = $this->getNotificationCount( $cached, $dbSource, EchoAttributeManager::ALERT );
		$count += $this->foreignNotifications->getCount( EchoAttributeManager::ALERT );

		return $count;
	}

getNotificationCount uses memcached if $cached = true and queries up to a hundred DB rows if $cached = false. OTOH, foreignNotifications->getCount() is not cached at all; it selects one row per wiki where the user has unread notifications, and each row contains the number of notifications on that wiki. That could potentially also be in the hundreds of rows, but it's unlikely to be more than a dozen.

Should we cache this in memcached too? My gut says it can't hurt, especially since we already do a getMulti() to memc so there would be essentially zero additional cost to add a few more keys to that.

Details

Related Gerrit Patches:

Event Timeline

Catrope created this task.Apr 26 2016, 12:41 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 26 2016, 12:41 AM
Catrope added a subscriber: ori.Apr 26 2016, 12:41 AM
ori added a comment.Apr 26 2016, 12:44 AM

Should we cache this in memcached too? My gut says it can't hurt, especially since we already do a getMulti() to memc so there would be essentially zero additional cost to add a few more keys to that.

Yes, agreed.

Catrope renamed this task from Cache foreign notification count in memcached? to Cache foreign notification count in memcached.Apr 26 2016, 1:30 AM

Probably the best way to do this would be to have a global memc key containing the total global notification count.

Catrope claimed this task.Apr 27 2016, 4:14 AM
Catrope moved this task from Untriaged to In Development on the Collab-Team-2016-Apr-Jun-Q4 board.

Change 285598 had a related patch set uploaded (by Catrope):
NotifUser: Refactor getNotificationCount() and friends, add caching for global counts

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

Change 285598 merged by jenkins-bot:
NotifUser: Refactor getNotificationCount() and friends, add caching for global counts

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

jmatazzoni closed this task as Resolved.May 12 2016, 5:42 PM