Catrope has uploaded a new change for review. https://gerrit.wikimedia.org/r/288136
Change subject: Don't cache pages with outdated global notification counts ...................................................................... Don't cache pages with outdated global notification counts When updating notification counts, we already called User::invalidateCache(), which bumps the local user's touched timestamp, which is taken into account by OutputPage when computing the last-modified timestamp of the response. However, this only works for one wiki, while the changed global count needs to be displayed on every wiki. To accomplish this, track the timestamp of the last update in NotifUser, and hook it into OutputPageCheckLastModified. Change-Id: I22c88a017f18a28179906049ee423c2d7e81c939 --- M Echo.php M Hooks.php M includes/NotifUser.php 3 files changed, 47 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/36/288136/1 diff --git a/Echo.php b/Echo.php index 887d584..c939b31 100644 --- a/Echo.php +++ b/Echo.php @@ -81,6 +81,7 @@ $wgHooks['ParserTestTables'][] = 'EchoHooks::onParserTestTables'; $wgHooks['EmailUserComplete'][] = 'EchoHooks::onEmailUserComplete'; $wgHooks['LoginFormValidErrorMessages'][] = 'EchoHooks::onLoginFormValidErrorMessages'; +$wgHooks['OutputPageCheckLastModified'][] = 'EchoHooks::onOutputPageCheckLastModified'; // Extension:UserMerge support $wgHooks['UserMergeAccountFields'][] = 'EchoHooks::onUserMergeAccountFields'; diff --git a/Hooks.php b/Hooks.php index 36f2f29..8a7fe6a 100644 --- a/Hooks.php +++ b/Hooks.php @@ -1002,6 +1002,18 @@ 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'] = $notifUser->getGlobalUpdateTime(); + } + } + } + /** * Handler for UnitTestsList hook. * @see http://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList diff --git a/includes/NotifUser.php b/includes/NotifUser.php index 1249759..cee5341 100644 --- a/includes/NotifUser.php +++ b/includes/NotifUser.php @@ -483,11 +483,10 @@ $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 ) { @@ -497,6 +496,38 @@ } /** + * 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 */ -- To view, visit https://gerrit.wikimedia.org/r/288136 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I22c88a017f18a28179906049ee423c2d7e81c939 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: Catrope <roan.katt...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits