From bf40d6267cca491fd4d575af4ec4b1db455840ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Thu, 5 Feb 2015 03:43:22 +0000 Subject: [PATCH] Add File::getDescriptionTouched() method Fetch page_touched timestamp of file description page via a DB query (possibly to a foreign DB). Not sure about the performance implications; could add a memcached layer on top, but the same DB lookup was already done for local files. Bug: T88648 Change-Id: I891c806aab235ff2c0e73c98b06b64fbe78e1517 --- includes/filerepo/file/File.php | 11 +++++++++++ includes/filerepo/file/LocalFile.php | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index df85f9c723..6ca61b26b7 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -2046,6 +2046,17 @@ abstract class File { return $this->repo->getFileTimestamp( $this->getPath() ); } + /** + * Returns the timestamp (in TS_MW format) of the last change of the description page. + * Returns false if the file does not have a description page, or retrieving the timestamp + * would be expensive. + * @since 1.25 + * @return string|bool + */ + public function getDescriptionTouched() { + return false; + } + /** * Get the SHA-1 base 36 hash of the file * diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index b2e5b00fa4..699c9154a2 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -109,6 +109,9 @@ class LocalFile extends File { /** @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; @@ -1777,6 +1780,22 @@ class LocalFile extends File { 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 */ -- 2.20.1