From 946cb44dc5ac73f6ebc38e526d6b44edf157ab45 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 5 Dec 2013 13:40:14 -0800 Subject: [PATCH] Added a TIME_ONLY option to FileRepo::findFiles to use less RAM * Also renamed $possFile to just $file in method Change-Id: Idb497901b9a7bd96c828267769a66efa282c5918 --- includes/filerepo/FileRepo.php | 11 ++++++++--- includes/filerepo/LocalRepo.php | 22 ++++++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index f62db89d4f..f834be5557 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -40,6 +40,8 @@ class FileRepo { const OVERWRITE_SAME = 4; const SKIP_LOCKING = 8; + const TIME_ONLY = 1; + /** @var bool Whether to fetch commons image description pages and display * them on the local wiki */ public $fetchDescription; @@ -474,9 +476,11 @@ class FileRepo { * $repo->findFiles( $findBatch ); * * No title should appear in $items twice, as the result use titles as keys - * @return array (Map of file names => File objects) for matches + * @param int $flags Supports: + * - FileRepo::TIME_ONLY : return a (file name => timestamp) map instead + * @return array Map of (file name => File objects) for matches */ - public function findFiles( array $items ) { + public function findFiles( array $items, $flags = 0 ) { $result = array(); foreach ( $items as $item ) { if ( is_array( $item ) ) { @@ -489,7 +493,8 @@ class FileRepo { } $file = $this->findFile( $title, $options ); if ( $file ) { - $result[$file->getTitle()->getDBkey()] = $file; + $result[$file->getTitle()->getDBkey()] = + ( $flags & self::TIME_ONLY ) ? $file->getTimestamp() : $file; } } diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index aa851ffbf8..e38f71df17 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -240,7 +240,7 @@ class LocalRepo extends FileRepo { return $id; } - public function findFiles( array $items ) { + public function findFiles( array $items, $flags = 0 ) { $finalFiles = array(); // map of (DB key => corresponding File) for matches $searchSet = array(); // map of (DB key => normalized search params) @@ -268,14 +268,15 @@ class LocalRepo extends FileRepo { $repo = $this; $applyMatchingFiles = function( ResultWrapper $res, &$searchSet, &$finalFiles ) - use ( $repo, $fileMatchesSearch ) + use ( $repo, $fileMatchesSearch, $flags ) { foreach ( $res as $row ) { - $possFile = $repo->newFileFromRow( $row ); - $dbKey = $possFile->getName(); + $file = $repo->newFileFromRow( $row ); + $dbKey = $file->getName(); // There must have been a search for this DB Key - if ( $fileMatchesSearch( $possFile, $searchSet[$dbKey] ) ) { - $finalFiles[$dbKey] = $possFile; + if ( $fileMatchesSearch( $file, $searchSet[$dbKey] ) ) { + $finalFiles[$dbKey] = + ( $flags & FileRepo::TIME_ONLY ) ? $file->getTimestamp() : $file; unset( $searchSet[$dbKey] ); } } @@ -313,10 +314,11 @@ class LocalRepo extends FileRepo { $title = File::normalizeTitle( $dbKey ); $redir = $this->checkRedirect( $title ); // hopefully hits memcached if ( $redir && $redir->getNamespace() == NS_FILE ) { - $possFile = $this->newFile( $redir ); - if ( $possFile && $fileMatchesSearch( $possFile, $search ) ) { - $possFile->redirectedFrom( $title->getDBkey() ); - $finalFiles[$dbKey] = $possFile; + $file = $this->newFile( $redir ); + if ( $file && $fileMatchesSearch( $file, $search ) ) { + $file->redirectedFrom( $title->getDBkey() ); + $finalFiles[$dbKey] = + ( $flags & FileRepo::TIME_ONLY ) ? $file->getTimestamp() : $file; } } } -- 2.20.1