Merge "Truncate SHA-1 indexes"
[lhc/web/wiklou.git] / includes / filebackend / FileBackendStore.php
index 9311a90..5823326 100644 (file)
@@ -89,6 +89,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - content       : the raw file contents
         *   - dst           : destination storage path
         *   - overwrite     : overwrite any file that exists at the destination
+        *   - disposition   : Content-Disposition header value for the destination
         *   - async         : Status will be returned immediately if supported.
         *                     If the status is OK, then its value field will be
         *                     set to a FileBackendStoreOpHandle object.
@@ -105,7 +106,9 @@ abstract class FileBackendStore extends FileBackend {
                } else {
                        $status = $this->doCreateInternal( $params );
                        $this->clearCache( array( $params['dst'] ) );
-                       $this->deleteFileCache( $params['dst'] ); // persistent cache
+                       if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+                               $this->deleteFileCache( $params['dst'] ); // persistent cache
+                       }
                }
                wfProfileOut( __METHOD__ . '-' . $this->name );
                wfProfileOut( __METHOD__ );
@@ -125,6 +128,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - src           : source path on disk
         *   - dst           : destination storage path
         *   - overwrite     : overwrite any file that exists at the destination
+        *   - disposition   : Content-Disposition header value for the destination
         *   - async         : Status will be returned immediately if supported.
         *                     If the status is OK, then its value field will be
         *                     set to a FileBackendStoreOpHandle object.
@@ -141,7 +145,9 @@ abstract class FileBackendStore extends FileBackend {
                } else {
                        $status = $this->doStoreInternal( $params );
                        $this->clearCache( array( $params['dst'] ) );
-                       $this->deleteFileCache( $params['dst'] ); // persistent cache
+                       if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+                               $this->deleteFileCache( $params['dst'] ); // persistent cache
+                       }
                }
                wfProfileOut( __METHOD__ . '-' . $this->name );
                wfProfileOut( __METHOD__ );
@@ -161,6 +167,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - src           : source storage path
         *   - dst           : destination storage path
         *   - overwrite     : overwrite any file that exists at the destination
+        *   - disposition   : Content-Disposition header value for the destination
         *   - async         : Status will be returned immediately if supported.
         *                     If the status is OK, then its value field will be
         *                     set to a FileBackendStoreOpHandle object.
@@ -173,7 +180,9 @@ abstract class FileBackendStore extends FileBackend {
                wfProfileIn( __METHOD__ . '-' . $this->name );
                $status = $this->doCopyInternal( $params );
                $this->clearCache( array( $params['dst'] ) );
-               $this->deleteFileCache( $params['dst'] ); // persistent cache
+               if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+                       $this->deleteFileCache( $params['dst'] ); // persistent cache
+               }
                wfProfileOut( __METHOD__ . '-' . $this->name );
                wfProfileOut( __METHOD__ );
                return $status;
@@ -222,6 +231,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - src           : source storage path
         *   - dst           : destination storage path
         *   - overwrite     : overwrite any file that exists at the destination
+        *   - disposition   : Content-Disposition header value for the destination
         *   - async         : Status will be returned immediately if supported.
         *                     If the status is OK, then its value field will be
         *                     set to a FileBackendStoreOpHandle object.
@@ -235,7 +245,9 @@ abstract class FileBackendStore extends FileBackend {
                $status = $this->doMoveInternal( $params );
                $this->clearCache( array( $params['src'], $params['dst'] ) );
                $this->deleteFileCache( $params['src'] ); // persistent cache
-               $this->deleteFileCache( $params['dst'] ); // persistent cache
+               if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+                       $this->deleteFileCache( $params['dst'] ); // persistent cache
+               }
                wfProfileOut( __METHOD__ . '-' . $this->name );
                wfProfileOut( __METHOD__ );
                return $status;
@@ -280,8 +292,14 @@ abstract class FileBackendStore extends FileBackend {
                // Try to lock the source files for the scope of this function
                $scopeLockS = $this->getScopedFileLocks( $params['srcs'], LockManager::LOCK_UW, $status );
                if ( $status->isOK() ) {
-                       // Actually do the concatenation
+                       // Actually do the file concatenation...
+                       $start_time = microtime( true );
                        $status->merge( $this->doConcatenate( $params ) );
+                       $sec = microtime( true ) - $start_time;
+                       if ( !$status->isOK() ) {
+                               wfDebugLog( 'FileOperation', get_class( $this ) . " failed to concatenate " .
+                                       count( $params['srcs'] ) . " file(s) [$sec sec]" );
+                       }
                }
 
                wfProfileOut( __METHOD__ . '-' . $this->name );
@@ -998,6 +1016,7 @@ abstract class FileBackendStore extends FileBackend {
                $this->primeContainerCache( $performOps );
 
                // Actually attempt the operation batch...
+               $opts = $this->setConcurrencyFlags( $opts );
                $subStatus = FileOpBatch::attempt( $performOps, $opts, $this->fileJournal );
 
                // Merge errors into status fields
@@ -1108,6 +1127,20 @@ abstract class FileBackendStore extends FileBackend {
                return array();
        }
 
+       /**
+        * @see FileBackend::preloadCache()
+        */
+       final public function preloadCache( array $paths ) {
+               $fullConts = array(); // full container names
+               foreach ( $paths as $path ) {
+                       list( $fullCont, $r, $s ) = $this->resolveStoragePath( $path );
+                       $fullConts[] = $fullCont;
+               }
+               // Load from the persistent file and container caches
+               $this->primeContainerCache( $fullConts );
+               $this->primeFileCache( $paths );
+       }
+
        /**
         * @see FileBackend::clearCache()
         */
@@ -1446,7 +1479,9 @@ abstract class FileBackendStore extends FileBackend {
        }
 
        /**
-        * Set the cached stat info for a file path
+        * Set the cached stat info for a file path.
+        * Negatives (404s) are not cached. By not caching negatives, we can skip cache
+        * salting for the case when a file is created at a path were there was none before.
         *
         * @param $path string Storage path
         * @param $val mixed Information to cache
@@ -1512,6 +1547,26 @@ abstract class FileBackendStore extends FileBackend {
                wfProfileOut( __METHOD__ . '-' . $this->name );
                wfProfileOut( __METHOD__ );
        }
+
+       /**
+        * Set the 'concurrency' option from a list of operation options
+        *
+        * @param $opts array Map of operation options
+        * @return Array
+        */
+       final protected function setConcurrencyFlags( array $opts ) {
+               $opts['concurrency'] = 1; // off
+               if ( $this->parallelize === 'implicit' ) {
+                       if ( !isset( $opts['parallelize'] ) || $opts['parallelize'] ) {
+                               $opts['concurrency'] = $this->concurrency;
+                       }
+               } elseif ( $this->parallelize === 'explicit' ) {
+                       if ( !empty( $opts['parallelize'] ) ) {
+                               $opts['concurrency'] = $this->concurrency;
+                       }
+               }
+               return $opts;
+       }
 }
 
 /**