Merge "Allow session expiry time to be configured"
[lhc/web/wiklou.git] / includes / filerepo / LocalRepo.php
index c616e16..0954422 100644 (file)
@@ -235,7 +235,8 @@ class LocalRepo extends FileRepo {
                        'image',
                        LocalFile::selectFields(),
                        array( 'img_sha1' => $hash ),
-                       __METHOD__
+                       __METHOD__,
+                       array( 'ORDER BY' => 'img_name' )
                );
                
                $result = array();
@@ -247,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