Reedy has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/338169 )
Change subject: Switch file store/delete operations to batch operations ...................................................................... Switch file store/delete operations to batch operations Bug: T157738 Change-Id: Ief109d78788fc9f6346e08661b973d65a035cafe --- M maintenance/GenerateFancyCaptchas.php 1 file changed, 51 insertions(+), 35 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit refs/changes/69/338169/1 diff --git a/maintenance/GenerateFancyCaptchas.php b/maintenance/GenerateFancyCaptchas.php index 4811692..1cc5244 100644 --- a/maintenance/GenerateFancyCaptchas.php +++ b/maintenance/GenerateFancyCaptchas.php @@ -126,15 +126,15 @@ ) ); - $originalFiles = []; + $filesToDelete = []; if ( $deleteOldCaptchas ) { - $this->output( "Getting a list of old captchas..." ); - foreach ( - $backend->getFileList( - [ 'dir' => $backend->getRootStoragePath() . '/captcha-render' ] - ) as $file - ) { - $originalFiles[] = $file; + $this->output( "Getting a list of old captchas to delete..." ); + $path = $backend->getRootStoragePath() . '/captcha-render'; + foreach ( $backend->getFileList( [ 'dir' => $path ] ) as $file ) { + $filesToDelete[] = [ + 'op' => 'delete', + 'src' => $path . '/' . $file, + ]; } $this->output( " Done.\n" ); } @@ -151,6 +151,10 @@ ); $captchasGenerated = iterator_count( $iter ); + $filesToStore = []; + /** + * @var $fileInfo SplFileInfo + */ foreach ( $iter as $fileInfo ) { if ( !$fileInfo->isFile() ) { continue; @@ -158,41 +162,53 @@ list( $salt, $hash ) = $instance->hashFromImageName( $fileInfo->getBasename() ); $dest = $instance->imagePath( $salt, $hash ); $backend->prepare( [ 'dir' => dirname( $dest ) ] ); - $status = $backend->quickStore( [ + $filesToStore[] = [ + 'op' => 'store', 'src' => $fileInfo->getPathname(), - 'dst' => $dest - ] ); - if ( !$status->isOK() ) { - $this->error( "Could not save file '{$fileInfo->getPathname()}'.\n" ); - } + 'dst' => $dest, + ]; } + + $ret = $backend->doQuickOperations( $filesToStore ); + $storeTime += microtime( true ); - $this->output( " Done.\n" ); - $this->output( - sprintf( - "\nCopied %d captchas to storage in %.1f seconds\n", - $captchasGenerated, - $storeTime - ) - ); - - if ( $deleteOldCaptchas ) { - $numOriginalFiles = count( $originalFiles ); - $this->output( "Deleting {$numOriginalFiles} old captchas...\n" ); - $deleteTime = -microtime( true ); - foreach ( $originalFiles as $file ) { - $backend->quickDelete( [ 'src' => $file ] ); - } - $deleteTime += microtime( true ); - $this->output( "Done.\n" ); + if ( $ret->isOK() ) { + $this->output( " Done.\n" ); $this->output( sprintf( - "\nDeleted %d old captchas in %.1f seconds\n", - count( $originalFiles ), - $deleteTime + "\nCopied %d captchas to storage in %.1f seconds\n", + $captchasGenerated, + $storeTime ) ); + } else { + $this->output( "Errored.\n" ); + $this->output( implode( "\n", $ret->getErrors() ) ); + } + + if ( $deleteOldCaptchas ) { + $numOriginalFiles = count( $filesToDelete ); + $this->output( "Deleting {$numOriginalFiles} old captchas...\n" ); + $deleteTime = -microtime( true ); + $ret = $backend->doQuickOperations( $filesToDelete ); + + $deleteTime += microtime( true ); + if ( $ret->isOK() ) { + + $this->output( "Done.\n" ); + $this->output( + sprintf( + "\nDeleted %d old captchas in %.1f seconds\n", + $numOriginalFiles, + $deleteTime + ) + ); + } else { + $this->output( "Errored.\n" ); + $this->output( implode( "\n", $ret->getErrors() ) ); + } + } } catch ( Exception $e ) { wfRecursiveRemoveDir( $tmpDir ); -- To view, visit https://gerrit.wikimedia.org/r/338169 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ief109d78788fc9f6346e08661b973d65a035cafe Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ConfirmEdit Gerrit-Branch: master Gerrit-Owner: Reedy <re...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits