X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fcache%2FMessageBlobStore.php;h=b262eab6024907a4f9664b702bec1866c20bf7b5;hb=97402532d48de203925a850a4afa2d8f43e3dd9f;hp=a2e46d30d44fbad199278ac42b29deddf22b73a5;hpb=772f90f38f1463e939db4a3f0ed42dcf4029dd1a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/cache/MessageBlobStore.php b/includes/cache/MessageBlobStore.php index a2e46d30d4..b262eab602 100644 --- a/includes/cache/MessageBlobStore.php +++ b/includes/cache/MessageBlobStore.php @@ -26,6 +26,7 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use Wikimedia\Rdbms\Database; /** * This class generates message blobs for use by ResourceLoader modules. @@ -75,7 +76,7 @@ class MessageBlobStore implements LoggerAwareInterface { * @return string JSON */ public function getBlob( ResourceLoaderModule $module, $lang ) { - $blobs = $this->getBlobs( array( $module->getName() => $module ), $lang ); + $blobs = $this->getBlobs( [ $module->getName() => $module ], $lang ); return $blobs[$module->getName()]; } @@ -92,27 +93,24 @@ class MessageBlobStore implements LoggerAwareInterface { // check key without language code. This is used to invalidate any and all language subkeys // that exist for a module from the updateMessage() method. $cache = $this->wanCache; - $checkKeys = array( + $checkKeys = [ // Global check key, see clear() $cache->makeKey( __CLASS__ ) - ); - $cacheKeys = array(); + ]; + $cacheKeys = []; foreach ( $modules as $name => $module ) { $cacheKey = $this->makeCacheKey( $module, $lang ); $cacheKeys[$name] = $cacheKey; // Per-module check key, see updateMessage() $checkKeys[$cacheKey][] = $cache->makeKey( __CLASS__, $name ); } - $curTTLs = array(); + $curTTLs = []; $result = $cache->getMulti( array_values( $cacheKeys ), $curTTLs, $checkKeys ); - $blobs = array(); + $blobs = []; foreach ( $modules as $name => $module ) { $key = $cacheKeys[$name]; if ( !isset( $result[$key] ) || $curTTLs[$key] === null || $curTTLs[$key] < 0 ) { - $this->logger->info( 'Message blob cache-miss for {module}', - array( 'module' => $name, 'cacheKey' => $key ) - ); $blobs[$name] = $this->recacheMessageBlob( $key, $module, $lang ); } else { // Use unexpired cache @@ -130,14 +128,6 @@ class MessageBlobStore implements LoggerAwareInterface { return $this->getBlobs( $modules, $lang ); } - /** - * @deprecated since 1.27 Obsolete. Used to populate a cache table in the database. - * @return bool - */ - public function insertMessageBlob( $name, ResourceLoaderModule $module, $lang ) { - return false; - } - /** * @since 1.27 * @param ResourceLoaderModule $module @@ -165,7 +155,7 @@ class MessageBlobStore implements LoggerAwareInterface { $cache->set( $cacheKey, $blob, // Add part of a day to TTL to avoid all modules expiring at once $cache::TTL_WEEK + mt_rand( 0, $cache::TTL_DAY ), - Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ) + Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) ) ); return $blob; } @@ -179,7 +169,7 @@ class MessageBlobStore implements LoggerAwareInterface { public function updateMessage( $key ) { $moduleNames = $this->getResourceLoader()->getModulesByMessage( $key ); foreach ( $moduleNames as $moduleName ) { - // Uses a holdoff to account for database slave lag (for MessageCache) + // Uses a holdoff to account for database replica DB lag (for MessageCache) $this->wanCache->touchCheckKey( $this->wanCache->makeKey( __CLASS__, $moduleName ) ); } } @@ -219,10 +209,10 @@ class MessageBlobStore implements LoggerAwareInterface { $message = wfMessage( $key )->inLanguage( $lang ); $value = $message->plain(); if ( !$message->exists() ) { - $this->logger->warning( 'Failed to find {messageKey} ({lang})', array( + $this->logger->warning( 'Failed to find {messageKey} ({lang})', [ 'messageKey' => $key, 'lang' => $lang, - ) ); + ] ); } return $value; } @@ -235,19 +225,21 @@ class MessageBlobStore implements LoggerAwareInterface { * @return string JSON blob */ private function generateMessageBlob( ResourceLoaderModule $module, $lang ) { - $messages = array(); + $messages = []; foreach ( $module->getMessages() as $key ) { $messages[$key] = $this->fetchMessage( $key, $lang ); } $json = FormatJson::encode( (object)$messages ); + // @codeCoverageIgnoreStart if ( $json === false ) { - $this->logger->warning( 'Failed to encode message blob for {module} ({lang})', array( + $this->logger->warning( 'Failed to encode message blob for {module} ({lang})', [ 'module' => $module->getName(), 'lang' => $lang, - ) ); + ] ); $json = '{}'; } + // codeCoverageIgnoreEnd return $json; } }