From 70b38d4d2bb0e156578d233a5c8c3796c7d3c1ba Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 25 Jun 2018 13:16:15 +0100 Subject: [PATCH] Make MessageCache use APC for big messages Bug: T118893 Change-Id: I418d0ca490911d7ee4213fe1728cfbc637ef8b10 --- includes/cache/MessageCache.php | 75 ++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index 48aac7ea32..7a172bead8 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -1028,40 +1028,47 @@ class MessageCache { * @return string Either " " or "!NONEXISTANT" */ private function loadCachedMessagePageEntry( $dbKey, $code, $hash ) { - return $this->wanCache->getWithSetCallback( - $this->bigMessageCacheKey( $hash, $dbKey ), - $this->mExpiry, - function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code ) { - // Try loading the message from the database - $dbr = wfGetDB( DB_REPLICA ); - $setOpts += Database::getCacheSetOptions( $dbr ); - // Use newKnownCurrent() to avoid querying revision/user tables - $title = Title::makeTitle( NS_MEDIAWIKI, $dbKey ); - $revision = Revision::newKnownCurrent( $dbr, $title ); - if ( !$revision ) { - // The wiki doesn't have a local override page. Cache absence with normal TTL. - // When overrides are created, self::replace() takes care of the cache. - return '!NONEXISTENT'; - } - $content = $revision->getContent(); - if ( $content ) { - $message = $this->getMessageTextFromContent( $content ); - } else { - LoggerFactory::getInstance( 'MessageCache' )->warning( - __METHOD__ . ': failed to load page text for \'{titleKey}\'', - [ 'titleKey' => $dbKey, 'code' => $code ] - ); - $message = null; - } - - if ( !is_string( $message ) ) { - // Revision failed to load Content, or Content is incompatible with wikitext. - // Possibly a temporary loading failure. - $ttl = 5; - return '!NONEXISTENT'; - } - - return ' ' . $message; + return $this->srvCache->getWithSetCallback( + $this->srvCache->makeKey( 'messages-big', $hash, $dbKey ), + IExpiringStore::TTL_MINUTE, + function () use ( $code, $dbKey, $hash ) { + return $this->wanCache->getWithSetCallback( + $this->bigMessageCacheKey( $hash, $dbKey ), + $this->mExpiry, + function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code ) { + // Try loading the message from the database + $dbr = wfGetDB( DB_REPLICA ); + $setOpts += Database::getCacheSetOptions( $dbr ); + // Use newKnownCurrent() to avoid querying revision/user tables + $title = Title::makeTitle( NS_MEDIAWIKI, $dbKey ); + $revision = Revision::newKnownCurrent( $dbr, $title ); + if ( !$revision ) { + // The wiki doesn't have a local override page. Cache absence with normal TTL. + // When overrides are created, self::replace() takes care of the cache. + return '!NONEXISTENT'; + } + $content = $revision->getContent(); + if ( $content ) { + $message = $this->getMessageTextFromContent( $content ); + } else { + LoggerFactory::getInstance( 'MessageCache' )->warning( + __METHOD__ . ': failed to load page text for \'{titleKey}\'', + [ 'titleKey' => $dbKey, 'code' => $code ] + ); + $message = null; + } + + if ( !is_string( $message ) ) { + // Revision failed to load Content, or Content is incompatible with wikitext. + // Possibly a temporary loading failure. + $ttl = 5; + + return '!NONEXISTENT'; + } + + return ' ' . $message; + } + ); } ); } -- 2.20.1