Simplify LocalFile::isVolatile
authorOri Livneh <ori@wikimedia.org>
Thu, 24 Apr 2014 22:57:09 +0000 (15:57 -0700)
committerOri Livneh <ori@wikimedia.org>
Thu, 24 Apr 2014 22:57:09 +0000 (15:57 -0700)
Make the logic a bit easier to follow. Follow-up to I99a39c3d2.

Change-Id: I9b815d7f0d229ef25db5b7f48f6e49ca4dac046e

includes/filerepo/file/LocalFile.php

index 5fd5512..e3b73e3 100644 (file)
@@ -1929,18 +1929,17 @@ class LocalFile extends File {
                global $wgMemc;
 
                $key = $this->repo->getSharedCacheKey( 'file-volatile', md5( $this->getName() ) );
-               if ( $key ) {
-                       if ( $this->lastMarkedVolatile
-                               && ( time() - $this->lastMarkedVolatile ) <= self::VOLATILE_TTL
-                       ) {
-                               return true; // sanity
-                       }
-                       $volatileTimestamp = (int)$wgMemc->get( $key );
-                       $this->lastMarkedVolatile = max( $this->lastMarkedVolatile, $volatileTimestamp );
-                       return ( $volatileTimestamp != 0 );
+               if ( !$key ) {
+                       // repo unavailable; bail.
+                       return false;
+               }
+
+               if ( $this->lastMarkedVolatile === 0 ) {
+                       $this->lastMarkedVolatile = $wgMemc->get( $key ) ?: 0;
                }
 
-               return false;
+               $volatileDuration = time() - $this->lastMarkedVolatile;
+               return $volatileDuration <= self::VOLATILE_TTL;
        }
 
        /**