From: umherirrender Date: Wed, 1 Aug 2012 17:51:23 +0000 (+0200) Subject: Add localonly= to prop duplicatefiles and imageinfo X-Git-Tag: 1.31.0-rc.0~22885^2 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=a57ea5c3ada37a5cb929677dd5ad4bd02e951522;p=lhc%2Fweb%2Fwiklou.git Add localonly= to prop duplicatefiles and imageinfo When looking only for local files, the localonly param skipped the mabye expensive look up inside the file repos. Change-Id: Ib8f38d6abf9238a349bbfd617a36933bdfe74b5c --- diff --git a/includes/api/ApiQueryDuplicateFiles.php b/includes/api/ApiQueryDuplicateFiles.php index 719c84a7b4..a4efc4c1c3 100644 --- a/includes/api/ApiQueryDuplicateFiles.php +++ b/includes/api/ApiQueryDuplicateFiles.php @@ -82,7 +82,12 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { } } - $files = RepoGroup::singleton()->findFiles( array_keys( $images ) ); + $filesToFind = array_keys( $images ); + if( $params['localonly'] ) { + $files = RepoGroup::singleton()->getLocalRepo()->findFiles( $filesToFind ); + } else { + $files = RepoGroup::singleton()->findFiles( $filesToFind ); + } $fit = true; $count = 0; @@ -94,7 +99,12 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { } // find all files with the hashes, result format is: array( hash => array( dup1, dup2 ), hash1 => ... ) - $filesBySha1s = RepoGroup::singleton()->findBySha1s( array_unique( array_values( $sha1s ) ) ); + $filesToFindBySha1s = array_unique( array_values( $sha1s ) ); + if( $params['localonly'] ) { + $filesBySha1s = RepoGroup::singleton()->getLocalRepo()->findBySha1s( $filesToFindBySha1s ); + } else { + $filesBySha1s = RepoGroup::singleton()->findBySha1s( $filesToFindBySha1s ); + } // iterate over $images to handle continue param correct foreach( $images as $image => $pageId ) { @@ -163,6 +173,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { 'descending' ) ), + 'localonly' => false, ); } @@ -171,6 +182,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { 'limit' => 'How many duplicate files to return', 'continue' => 'When more results are available, use this to continue', 'dir' => 'The direction in which to list', + 'localonly' => 'Look only for files in the local repository', ); } diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 7184c887d6..d822eed555 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -73,7 +73,12 @@ class ApiQueryImageInfo extends ApiQueryBase { } $result = $this->getResult(); - $images = RepoGroup::singleton()->findFiles( $titles ); + //search only inside the local repo + if( $params['localonly'] ) { + $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $titles ); + } else { + $images = RepoGroup::singleton()->findFiles( $titles ); + } foreach ( $images as $img ) { // Skip redirects if ( $img->getOriginalTitle()->isRedirect() ) { @@ -471,6 +476,7 @@ class ApiQueryImageInfo extends ApiQueryBase { ApiBase::PARAM_TYPE => 'string', ), 'continue' => null, + 'localonly' => false, ); } @@ -543,7 +549,8 @@ class ApiQueryImageInfo extends ApiQueryBase { 'end' => 'Timestamp to stop listing at', 'metadataversion' => array( "Version of metadata to use. if 'latest' is specified, use latest version.", "Defaults to '1' for backwards compatibility" ), - 'continue' => 'If the query response includes a continue value, use it here to get another page of results' + 'continue' => 'If the query response includes a continue value, use it here to get another page of results', + 'localonly' => 'Look only for files in the local repository', ); }