X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilerepo%2FLocalRepo.php;h=118e9810c3ce564428f779c2349506fa8d46dbc7;hb=94ff2a3ccfd5da9ddb3af6470c88a3e937af2912;hp=dd0c947554471f69edb009fbadd4c32f2ccf4847;hpb=057563b96ac833c195150d72cffbdcf71b1660af;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index dd0c947554..118e9810c3 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -238,7 +238,7 @@ class LocalRepo extends FileRepo { __METHOD__, array( 'ORDER BY' => 'img_name' ) ); - + $result = array(); foreach ( $res as $row ) { $result[] = $this->newFileFromRow( $row ); @@ -248,6 +248,39 @@ class LocalRepo extends FileRepo { return $result; } + /** + * Get an array of arrays or iterators of file objects for files that + * have the given SHA-1 content hashes. + * + * Overrides generic implementation in FileRepo for performance reason + * + * @param $hashes array An array of hashes + * @return array An Array of arrays or iterators of file objects and the hash as key + */ + function findBySha1s( array $hashes ) { + if( !count( $hashes ) ) { + return array(); //empty parameter + } + + $dbr = $this->getSlaveDB(); + $res = $dbr->select( + 'image', + LocalFile::selectFields(), + array( 'img_sha1' => $hashes ), + __METHOD__, + array( 'ORDER BY' => 'img_name' ) + ); + + $result = array(); + foreach ( $res as $row ) { + $file = $this->newFileFromRow( $row ); + $result[$file->getSha1()][] = $file; + } + $res->free(); + + return $result; + } + /** * Get a connection to the slave DB * @return DatabaseBase @@ -266,7 +299,7 @@ class LocalRepo extends FileRepo { /** * Get a key on the primary cache for this repository. - * Returns false if the repository's cache is not accessible at this site. + * Returns false if the repository's cache is not accessible at this site. * The parameters are the parts of the key, as for wfMemcKey(). * * @return string