[MediaWiki-commits] [Gerrit] mediawiki...ConfirmEdit[master]: Switch file store/delete operations to batch operations

2017-02-26 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
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(-)

Approvals:
  Florianschmidtwelzow: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/GenerateFancyCaptchas.php 
b/maintenance/GenerateFancyCaptchas.php
index 43ad72f..9ab972b 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",
-   

[MediaWiki-commits] [Gerrit] mediawiki...ConfirmEdit[master]: Switch file store/delete operations to batch operations

2017-02-16 Thread Reedy (Code Review)
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",
-