Merge "Don't cache pages with outdated global notification counts"

This commit is contained in:
jenkins-bot 2016-05-11 18:08:53 +00:00 committed by Gerrit Code Review
commit 69967ae13a
3 changed files with 47 additions and 3 deletions

View file

@ -81,6 +81,7 @@ $wgHooks['UserClearNewTalkNotification'][] = 'EchoHooks::onUserClearNewTalkNotif
$wgHooks['ParserTestTables'][] = 'EchoHooks::onParserTestTables'; $wgHooks['ParserTestTables'][] = 'EchoHooks::onParserTestTables';
$wgHooks['EmailUserComplete'][] = 'EchoHooks::onEmailUserComplete'; $wgHooks['EmailUserComplete'][] = 'EchoHooks::onEmailUserComplete';
$wgHooks['LoginFormValidErrorMessages'][] = 'EchoHooks::onLoginFormValidErrorMessages'; $wgHooks['LoginFormValidErrorMessages'][] = 'EchoHooks::onLoginFormValidErrorMessages';
$wgHooks['OutputPageCheckLastModified'][] = 'EchoHooks::onOutputPageCheckLastModified';
// Extension:UserMerge support // Extension:UserMerge support
$wgHooks['UserMergeAccountFields'][] = 'EchoHooks::onUserMergeAccountFields'; $wgHooks['UserMergeAccountFields'][] = 'EchoHooks::onUserMergeAccountFields';

View file

@ -1002,6 +1002,18 @@ class EchoHooks {
return true; return true;
} }
public static function onOutputPageCheckLastModified( array &$modifiedTimes ) {
// HACK: this hook doesn't pass in a ContextSource
$user = RequestContext::getMain()->getUser();
if ( $user->isLoggedIn() ) {
$notifUser = MWEchoNotifUser::newFromUser( $user );
$lastUpdate = $notifUser->getGlobalUpdateTime();
if ( $lastUpdate !== false ) {
$modifiedTimes['notifications'] = $lastUpdate;
}
}
}
/** /**
* Handler for UnitTestsList hook. * Handler for UnitTestsList hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList * @see http://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList

View file

@ -483,11 +483,10 @@ class MWEchoNotifUser {
$this->setInCache( $this->getGlobalMemcKey( 'echo-notification-timestamp-message' ), $globalMsgUnread === false ? -1 : $globalMsgUnread->getTimestamp( TS_MW ), 86400 ); $this->setInCache( $this->getGlobalMemcKey( 'echo-notification-timestamp-message' ), $globalMsgUnread === false ? -1 : $globalMsgUnread->getTimestamp( TS_MW ), 86400 );
$this->setInCache( $this->getGlobalMemcKey( 'echo-notification-timestamp' ), $globalAllUnread === false ? -1 : $globalAllUnread->getTimestamp( TS_MW ), 86400 ); $this->setInCache( $this->getGlobalMemcKey( 'echo-notification-timestamp' ), $globalAllUnread === false ? -1 : $globalAllUnread->getTimestamp( TS_MW ), 86400 );
// Invalidate the user's cache $this->invalidateCache();
$user = $this->mUser;
$user->invalidateCache();
// Schedule an update to the echo_unread_wikis table // Schedule an update to the echo_unread_wikis table
$user = $this->mUser;
DeferredUpdates::addCallableUpdate( function () use ( $user, $alertCount, $alertUnread, $msgCount, $msgUnread ) { DeferredUpdates::addCallableUpdate( function () use ( $user, $alertCount, $alertUnread, $msgCount, $msgUnread ) {
$uw = EchoUnreadWikis::newFromUser( $user ); $uw = EchoUnreadWikis::newFromUser( $user );
if ( $uw ) { if ( $uw ) {
@ -496,6 +495,38 @@ class MWEchoNotifUser {
} ); } );
} }
/**
* Get the timestamp of the last time the global notification counts/timestamps were updated, if available.
*
* If the timestamp of the last update is not known, this will return the current timestamp.
* If the user is not attached, this will return false.
*
* @return string|false MW timestamp of the last update, or false if the user is not attached
*/
public function getGlobalUpdateTime() {
$key = $this->getGlobalMemcKey( 'echo-notification-updated' );
if ( $key === false ) {
return false;
}
return wfTimestamp( TS_MW, ObjectCache::getMainWANInstance()->getCheckKeyTime( $key ) );
}
/**
* Invalidate user caches related to notification counts/timestamps.
*
* This bumps the local user's touched timestamp as well as the timestamp returned by getGlobalUpdateTime().
*/
protected function invalidateCache() {
// Update the user touched timestamp for the local user
$this->mUser->invalidateCache();
// Update the global touched timestamp
$key = $this->getGlobalMemcKey( 'echo-notification-updated' );
if ( $key ) {
ObjectCache::getMainWANInstance()->touchCheckKey( $key );
}
}
/** /**
* Get the user's email notification format * Get the user's email notification format
* @return string * @return string