mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
Merge "Don't cache pages with outdated global notification counts"
This commit is contained in:
commit
69967ae13a
1
Echo.php
1
Echo.php
|
@ -81,6 +81,7 @@ $wgHooks['UserClearNewTalkNotification'][] = 'EchoHooks::onUserClearNewTalkNotif
|
|||
$wgHooks['ParserTestTables'][] = 'EchoHooks::onParserTestTables';
|
||||
$wgHooks['EmailUserComplete'][] = 'EchoHooks::onEmailUserComplete';
|
||||
$wgHooks['LoginFormValidErrorMessages'][] = 'EchoHooks::onLoginFormValidErrorMessages';
|
||||
$wgHooks['OutputPageCheckLastModified'][] = 'EchoHooks::onOutputPageCheckLastModified';
|
||||
|
||||
// Extension:UserMerge support
|
||||
$wgHooks['UserMergeAccountFields'][] = 'EchoHooks::onUserMergeAccountFields';
|
||||
|
|
12
Hooks.php
12
Hooks.php
|
@ -1002,6 +1002,18 @@ class EchoHooks {
|
|||
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.
|
||||
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
|
||||
|
|
|
@ -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' ), $globalAllUnread === false ? -1 : $globalAllUnread->getTimestamp( TS_MW ), 86400 );
|
||||
|
||||
// Invalidate the user's cache
|
||||
$user = $this->mUser;
|
||||
$user->invalidateCache();
|
||||
$this->invalidateCache();
|
||||
|
||||
// Schedule an update to the echo_unread_wikis table
|
||||
$user = $this->mUser;
|
||||
DeferredUpdates::addCallableUpdate( function () use ( $user, $alertCount, $alertUnread, $msgCount, $msgUnread ) {
|
||||
$uw = EchoUnreadWikis::newFromUser( $user );
|
||||
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
|
||||
* @return string
|
||||
|
|
Loading…
Reference in a new issue