Fix timestamp check in ApiStashEdit::checkCache
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 27 Apr 2016 22:43:38 +0000 (15:43 -0700)
committerOri.livneh <ori@wikimedia.org>
Thu, 28 Apr 2016 22:01:03 +0000 (22:01 +0000)
* 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
includes/page/WikiPage.php
includes/parser/ParserCache.php
includes/parser/ParserOutput.php

index cc8e390..f5d57c1 100644 (file)
@@ -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;
        }
index 06785b7..040a6f3 100644 (file)
@@ -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;
        }
 
index 731d4a0..5876e0b 100644 (file)
@@ -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" );
index 40c67dd..6c7ad4e 100644 (file)
@@ -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;
        }