Revert "Use display name in category page subheadings if provided"
[lhc/web/wiklou.git] / includes / filebackend / FileBackendMultiWrite.php
index 5a103c6..3b20048 100644 (file)
@@ -178,7 +178,9 @@ class FileBackendMultiWrite extends FileBackend {
                        wfDebugLog( 'FileOperation', get_class( $this ) .
                                " failed sync check: " . FormatJson::encode( $relevantPaths ) );
                        // Try to resync the clone backends to the master on the spot...
-                       if ( !$this->autoResync || !$this->resyncFiles( $relevantPaths )->isOK() ) {
+                       if ( $this->autoResync === false
+                               || !$this->resyncFiles( $relevantPaths, $this->autoResync )->isOK()
+                       ) {
                                $status->merge( $syncStatus );
 
                                return $status; // abort
@@ -202,11 +204,17 @@ class FileBackendMultiWrite extends FileBackend {
                                if ( $this->asyncWrites && !$this->hasVolatileSources( $ops ) ) {
                                        // Bind $scopeLock to the callback to preserve locks
                                        DeferredUpdates::addCallableUpdate(
-                                               function() use ( $backend, $realOps, $opts, $scopeLock ) {
+                                               function() use ( $backend, $realOps, $opts, $scopeLock, $relevantPaths ) {
+                                                       wfDebugLog( 'FileOperationReplication',
+                                                               "'{$backend->getName()}' async replication; paths: " .
+                                                               FormatJson::encode( $relevantPaths ) );
                                                        $backend->doOperations( $realOps, $opts );
                                                }
                                        );
                                } else {
+                                       wfDebugLog( 'FileOperationReplication',
+                                               "'{$backend->getName()}' sync replication; paths: " .
+                                               FormatJson::encode( $relevantPaths ) );
                                        $status->merge( $backend->doOperations( $realOps, $opts ) );
                                }
                        }
@@ -233,6 +241,12 @@ class FileBackendMultiWrite extends FileBackend {
                        return $status; // skip checks
                }
 
+               // Preload all of the stat info in as few round trips as possible...
+               foreach ( $this->backends as $backend ) {
+                       $realPaths = $this->substPaths( $paths, $backend );
+                       $backend->preloadFileStat( [ 'srcs' => $realPaths, 'latest' => true ] );
+               }
+
                $mBackend = $this->backends[$this->masterIndex];
                foreach ( $paths as $path ) {
                        $params = [ 'src' => $path, 'latest' => true ];
@@ -316,9 +330,10 @@ class FileBackendMultiWrite extends FileBackend {
         * and re-synchronize those files against the "multi master" if needed.
         *
         * @param array $paths List of storage paths
+        * @param string|bool $resyncMode False, True, or "conservative"; see __construct()
         * @return Status
         */
-       public function resyncFiles( array $paths ) {
+       public function resyncFiles( array $paths, $resyncMode = true ) {
                $status = Status::newGood();
 
                $mBackend = $this->backends[$this->masterIndex];
@@ -349,7 +364,7 @@ class FileBackendMultiWrite extends FileBackend {
                                if ( $mSha1 === $cSha1 ) {
                                        // already synced; nothing to do
                                } elseif ( $mSha1 !== false ) { // file is in master
-                                       if ( $this->autoResync === 'conservative'
+                                       if ( $resyncMode === 'conservative'
                                                && $cStat && $cStat['mtime'] > $mStat['mtime']
                                        ) {
                                                $status->fatal( 'backend-fail-synced', $path );
@@ -361,7 +376,7 @@ class FileBackendMultiWrite extends FileBackend {
                                                [ 'src' => $fsFile->getPath(), 'dst' => $cPath ]
                                        ) );
                                } elseif ( $mStat === false ) { // file is not in master
-                                       if ( $this->autoResync === 'conservative' ) {
+                                       if ( $resyncMode === 'conservative' ) {
                                                $status->fatal( 'backend-fail-synced', $path );
                                                continue; // don't delete data
                                        }
@@ -370,6 +385,11 @@ class FileBackendMultiWrite extends FileBackend {
                        }
                }
 
+               if ( !$status->isOK() ) {
+                       wfDebugLog( 'FileOperation', get_class( $this ) .
+                               " failed to resync: " . FormatJson::encode( $paths ) );
+               }
+
                return $status;
        }