/** @var string Description of current revision of the file */
private $description;
+ /** @var string TS_MW timestamp of the last change of the file description */
+ private $descriptionTouched;
+
/** @var bool Whether the row was upgraded on load */
private $upgraded;
/** @var bool True if file is not present in file system. Not to be cached in memcached */
private $missing;
- /** @var int UNIX timestamp of last markVolatile() call */
- private $lastMarkedVolatile = 0;
-
- const LOAD_ALL = 1; // integer; load all the lazy fields too (like metadata)
- const LOAD_VIA_SLAVE = 2; // integer; use a slave to load the data
-
- const VOLATILE_TTL = 300; // integer; seconds
+ // @note: higher than IDBAccessObject constants
+ const LOAD_ALL = 16; // integer; load all the lazy fields too (like metadata)
/**
* Create a LocalFile from a title
$this->dataLoaded = true;
$this->extraDataLoaded = true;
- $dbr = ( $flags & self::LOAD_VIA_SLAVE )
- ? $this->repo->getSlaveDB()
- : $this->repo->getMasterDB();
+ $dbr = ( $flags & self::READ_LATEST )
+ ? $this->repo->getMasterDB()
+ : $this->repo->getSlaveDB();
$row = $dbr->selectRow( 'image', $this->getCacheFields( 'img_' ),
array( 'img_name' => $this->getName() ), $fname );
*/
function load( $flags = 0 ) {
if ( !$this->dataLoaded ) {
- if ( !$this->loadFromCache() ) {
- $this->loadFromDB( $this->isVolatile() ? 0 : self::LOAD_VIA_SLAVE );
+ if ( ( $flags & self::READ_LATEST ) || !$this->loadFromCache() ) {
+ $this->loadFromDB( $flags );
$this->saveToCache();
}
$this->dataLoaded = true;
}
if ( ( $flags & self::LOAD_ALL ) && !$this->extraDataLoaded ) {
+ // @note: loads on name/timestamp to reduce race condition problems
$this->loadExtraFromDB();
}
}
return $this->timestamp;
}
+ /**
+ * @return bool|string
+ */
+ public function getDescriptionTouched() {
+ // The DB lookup might return false, e.g. if the file was just deleted, or the shared DB repo
+ // itself gets it from elsewhere. To avoid repeating the DB lookups in such a case, we
+ // need to differentiate between null (uninitialized) and false (failed to load).
+ if ( $this->descriptionTouched === null ) {
+ $cond = array( 'page_namespace' => $this->title->getNamespace(), 'page_title' => $this->title->getDBkey() );
+ $touched = $this->repo->getSlaveDB()->selectField( 'page', 'page_touched', $cond, __METHOD__ );
+ $this->descriptionTouched = $touched ? wfTimestamp( TS_MW, $touched ) : false;
+ }
+
+ return $this->descriptionTouched;
+ }
+
/**
* @return string
*/
} );
}
- $this->markVolatile(); // file may change soon
-
return $this->lockedOwnTrx;
}
}
}
- /**
- * Mark a file as about to be changed
- *
- * This sets a cache key that alters master/slave DB loading behavior
- *
- * @return bool Success
- */
- protected function markVolatile() {
- global $wgMemc;
-
- $key = $this->repo->getSharedCacheKey( 'file-volatile', md5( $this->getName() ) );
- if ( $key ) {
- $this->lastMarkedVolatile = time();
- return $wgMemc->set( $key, $this->lastMarkedVolatile, self::VOLATILE_TTL );
- }
-
- return true;
- }
-
- /**
- * Check if a file is about to be changed or has been changed recently
- *
- * @see LocalFile::isVolatile()
- * @return bool Whether the file is volatile
- */
- protected function isVolatile() {
- global $wgMemc;
-
- $key = $this->repo->getSharedCacheKey( 'file-volatile', md5( $this->getName() ) );
- if ( !$key ) {
- // repo unavailable; bail.
- return false;
- }
-
- if ( $this->lastMarkedVolatile === 0 ) {
- $this->lastMarkedVolatile = $wgMemc->get( $key ) ?: 0;
- }
-
- $volatileDuration = time() - $this->lastMarkedVolatile;
- return $volatileDuration <= self::VOLATILE_TTL;
- }
-
/**
* Roll back the DB transaction and mark the image unlocked
*/