From: Gilles Dubuc Date: Tue, 23 May 2017 08:41:33 +0000 (+0200) Subject: Batch/pipeline backend operations in refreshFileHeaders X-Git-Tag: 1.31.0-rc.0~3141^2~3^2 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=e20e1c80d3435a8545a3e1e1cf818d6591abb98d;p=lhc%2Fweb%2Fwiklou.git Batch/pipeline backend operations in refreshFileHeaders Bug: T150741 Change-Id: I44efd47e7eb3eba71ae39808ee8e6969e141c5cc --- diff --git a/maintenance/refreshFileHeaders.php b/maintenance/refreshFileHeaders.php index b9b418cb2b..e252256ae3 100644 --- a/maintenance/refreshFileHeaders.php +++ b/maintenance/refreshFileHeaders.php @@ -48,11 +48,14 @@ class RefreshFileHeaders extends Maintenance { $count = 0; $dbr = $this->getDB( DB_REPLICA ); + do { $conds = [ "img_name > {$dbr->addQuotes( $start )}" ]; + if ( strlen( $end ) ) { $conds[] = "img_name <= {$dbr->addQuotes( $end )}"; } + $res = $dbr->select( 'image', '*', $conds, __METHOD__, [ 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'img_name ASC' ] ); @@ -62,34 +65,48 @@ class RefreshFileHeaders extends Maintenance { $res->rewind(); } + $backendOperations = []; + foreach ( $res as $row ) { $file = $repo->newFileFromRow( $row ); $headers = $file->getContentHeaders(); + if ( count( $headers ) ) { - $this->updateFileHeaders( $file, $headers ); + $backendOperations[] = [ + 'op' => 'describe', 'src' => $file->getPath(), 'headers' => $headers + ]; } + // Do all of the older file versions... foreach ( $file->getHistory() as $oldFile ) { $headers = $oldFile->getContentHeaders(); if ( count( $headers ) ) { - $this->updateFileHeaders( $oldFile, $headers ); + $backendOperations[] = [ + 'op' => 'describe', 'src' => $oldFile->getPath(), 'headers' => $headers + ]; } } + if ( $this->hasOption( 'verbose' ) ) { - $this->output( "Updated headers for file '{$row->img_name}'.\n" ); + $this->output( "Queued headers update for file '{$row->img_name}'.\n" ); } - ++$count; + $start = $row->img_name; // advance } + + $backendOperationsCount = count( $backendOperations ); + $count += $backendOperationsCount; + + $this->output( "Updating headers for {$backendOperationsCount} file(s).\n" ); + $this->updateFileHeaders( $repo, $backendOperations ); } while ( $res->numRows() === $this->mBatchSize ); $this->output( "Done. Updated headers for $count file(s).\n" ); } - protected function updateFileHeaders( File $file, array $headers ) { - $status = $file->getRepo()->getBackend()->describe( [ - 'src' => $file->getPath(), 'headers' => $headers - ] ); + protected function updateFileHeaders( $repo, $backendOperations ) { + $status = $repo->getBackend()->doQuickOperations( $backendOperations ); + if ( !$status->isGood() ) { $this->error( "Encountered error: " . print_r( $status, true ) ); }