From af349f79c8638927193f6bf52a101251e9eddbc3 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 27 Apr 2016 15:43:38 -0700 Subject: [PATCH] Fix timestamp check in ApiStashEdit::checkCache * The wrong time method was used, and it also was not set. * Bumped the threshold a bit while at it, which was basically 0-5 minutes before. Bug: T133332 Change-Id: Ide3e66f551aa6e50410c562e5c917141d59b7f64 --- includes/api/ApiStashEdit.php | 14 ++++++++------ includes/page/WikiPage.php | 6 ++++++ includes/parser/ParserCache.php | 1 + includes/parser/ParserOutput.php | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php index cc8e39079f..f5d57c19c1 100644 --- a/includes/api/ApiStashEdit.php +++ b/includes/api/ApiStashEdit.php @@ -40,6 +40,8 @@ class ApiStashEdit extends ApiBase { const ERROR_CACHE = 'error_cache'; const ERROR_UNCACHEABLE = 'uncacheable'; + const PRESUME_FRESH_TTL_SEC = 5; + public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); @@ -281,10 +283,10 @@ class ApiStashEdit extends ApiBase { return false; } - $time = wfTimestamp( TS_UNIX, $editInfo->output->getTimestamp() ); - if ( ( time() - $time ) <= 3 ) { + $age = time() - wfTimestamp( TS_UNIX, $editInfo->output->getCacheTime() ); + if ( $age <= self::PRESUME_FRESH_TTL_SEC ) { $stats->increment( 'editstash.cache_hits.presumed_fresh' ); - $logger->debug( "Timestamp-based cache hit for key '$key'." ); + $logger->debug( "Timestamp-based cache hit for key '$key' (age: $age sec)." ); return $editInfo; // assume nothing changed } @@ -313,7 +315,7 @@ class ApiStashEdit extends ApiBase { if ( $changed || $res->numRows() != $templateUses ) { $stats->increment( 'editstash.cache_misses.proven_stale' ); - $logger->info( "Stale cache for key '$key'; template changed." ); + $logger->info( "Stale cache for key '$key'; template changed. (age: $age sec)" ); return false; } } @@ -337,13 +339,13 @@ class ApiStashEdit extends ApiBase { if ( $changed || $res->numRows() != count( $files ) ) { $stats->increment( 'editstash.cache_misses.proven_stale' ); - $logger->info( "Stale cache for key '$key'; file changed." ); + $logger->info( "Stale cache for key '$key'; file changed. (age: $age sec)" ); return false; } } $stats->increment( 'editstash.cache_hits.proven_fresh' ); - $logger->debug( "Cache hit for key '$key'." ); + $logger->debug( "Verified cache hit for key '$key' (age: $age sec)." ); return $editInfo; } diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 06785b70e3..040a6f328a 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -2115,7 +2115,13 @@ class WikiPage implements Page, IDBAccessObject { : ''; $edit->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialFormat ) : ''; + if ( $edit->output ) { + $edit->output->setCacheTime( wfTimestampNow() ); + } + + // Process cache the result $this->mPreparedEdit = $edit; + return $edit; } diff --git a/includes/parser/ParserCache.php b/includes/parser/ParserCache.php index 731d4a0186..5876e0b258 100644 --- a/includes/parser/ParserCache.php +++ b/includes/parser/ParserCache.php @@ -204,6 +204,7 @@ class ParserCache { } $casToken = null; + /** @var ParserOutput $value */ $value = $this->mMemc->get( $parserOutputKey, $casToken, BagOStuff::READ_VERIFIED ); if ( !$value ) { wfDebug( "ParserOutput cache miss.\n" ); diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 40c67dd785..6c7ad4eb4c 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -381,6 +381,9 @@ class ParserOutput extends CacheTime { return $this->mTOCHTML; } + /** + * @return string|null TS_MW timestamp of the revision content + */ public function getTimestamp() { return $this->mTimestamp; } -- 2.20.1