Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/308917
Change subject: Revision: Simplify loadText() with nested getWithSetCallback ...................................................................... Revision: Simplify loadText() with nested getWithSetCallback The logic was a bit hard to follow as there were two layers of caching and a conditional (expiry being set). * Move fetch logic for revision text to a private method. * Call directly when cache is disabled. * Simplify cache has/get/set by using getWithSetCallback. Change-Id: Icd74cd8e944266c20dc7c5cb25f56300636dce1e --- M includes/Revision.php 1 file changed, 26 insertions(+), 26 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/17/308917/1 diff --git a/includes/Revision.php b/includes/Revision.php index 03c3e6d..3c78830 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -1079,13 +1079,14 @@ } /** - * Fetch original serialized data without regard for view restrictions + * Get original serialized data (without checking view restrictions) * * @since 1.21 * @return string */ public function getSerializedData() { if ( $this->mText === null ) { + // Revision is immutable. Load on demand. $this->mText = $this->loadText(); } @@ -1103,17 +1104,14 @@ */ protected function getContentInternal() { if ( $this->mContent === null ) { - // Revision is immutable. Load on demand: - if ( $this->mText === null ) { - $this->mText = $this->loadText(); - } + $text = $this->getSerializedData(); - if ( $this->mText !== null && $this->mText !== false ) { + if ( $text !== null && $text !== false ) { // Unserialize content $handler = $this->getContentHandler(); $format = $this->getContentFormat(); - $this->mContent = $handler->unserializeContent( $this->mText, $format ); + $this->mContent = $handler->unserializeContent( $text, $format ); } } @@ -1576,29 +1574,37 @@ * * @return string|bool The revision's text, or false on failure */ - protected function loadText() { + private function loadText() { // Caching may be beneficial for massive use of external storage global $wgRevisionCacheExpiry; static $processCache = null; + + if ( !$wgRevisionCacheExpiry ) { + return $this->fetchText(); + } if ( !$processCache ) { $processCache = new MapCacheLRU( 10 ); } $cache = ObjectCache::getMainWANInstance(); - $textId = $this->getTextId(); - $key = wfMemcKey( 'revisiontext', 'textid', $textId ); + $key = $cache->makeKey( 'revisiontext', 'textid', $this->getTextId() ); - if ( $wgRevisionCacheExpiry ) { - if ( $processCache->has( $key ) ) { - return $processCache->get( $key ); - } - $text = $cache->get( $key ); - if ( is_string( $text ) ) { - $processCache->set( $key, $text ); - return $text; - } + // No negative caching; negative hits on text rows may be due to corrupted replica DBs + if ( $processCache->has( $key ) ) { + return $processCache->get( $key ); } + $text = $cache->getWithSetCallback( $key, $wgRevisionCacheExpiry, function () { + return $this->fetchText(); + } ); + if ( $text !== false ) { + $processCache->set( $key, $text ); + } + return $text; + } + + private function fetchText() { + $textId = $this->getTextId(); // If we kept data for lazy extraction, use it now... if ( $this->mTextRow !== null ) { @@ -1638,13 +1644,7 @@ wfDebugLog( 'Revision', "No blob for text row '$textId' (revision {$this->getId()})." ); } - # No negative caching -- negative hits on text rows may be due to corrupted replica DB servers - if ( $wgRevisionCacheExpiry && $text !== false ) { - $processCache->set( $key, $text ); - $cache->set( $key, $text, $wgRevisionCacheExpiry ); - } - - return $text; + return is_string( $text ) ? $text : false; } /** -- To view, visit https://gerrit.wikimedia.org/r/308917 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icd74cd8e944266c20dc7c5cb25f56300636dce1e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits