jenkins-bot has submitted this change and it was merged.

Change subject: Made cleanupUploadStash use batching for the last two loops
......................................................................


Made cleanupUploadStash use batching for the last two loops

Change-Id: If3cfd333636f5b14c529629ce1ec408d396122a8
(cherry picked from commit 7c13cc0097d2cb78dc7ba869a64436f0cc9c2b45)
---
M maintenance/cleanupUploadStash.php
1 file changed, 28 insertions(+), 10 deletions(-)

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



diff --git a/maintenance/cleanupUploadStash.php 
b/maintenance/cleanupUploadStash.php
index bc43c67..00aea56 100644
--- a/maintenance/cleanupUploadStash.php
+++ b/maintenance/cleanupUploadStash.php
@@ -38,6 +38,7 @@
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Clean up abandoned files in temporary 
uploaded file stash";
+               $this->setBatchSize( 50 );
        }
 
        public function execute() {
@@ -97,16 +98,21 @@
                $iterator = $tempRepo->getBackend()->getFileList( array( 'dir' 
=> $dir ) );
                $this->output( "Deleting old thumbnails...\n" );
                $i = 0;
+               $batch = array(); // operation batch
                foreach ( $iterator as $file ) {
                        if ( wfTimestamp( TS_UNIX, $tempRepo->getFileTimestamp( 
"$dir/$file" ) ) < $cutoff ) {
-                               $status = $tempRepo->quickPurge( "$dir/$file" );
-                               if ( !$status->isOK() ) {
-                                       $this->error( print_r( 
$status->getErrorsArray(), true ) );
-                               }
-                               if ( ( ++$i % 100 ) == 0 ) {
+                               $batch[] = array( 'op' => 'delete', 'src' => 
"$dir/$file" );
+                               if ( count( $batch ) >= $this->mBatchSize ) {
+                                       $this->doOperations( $tempRepo, $batch 
);
+                                       $i += count( $batch );
+                                       $batch = array();
                                        $this->output( "$i\n" );
                                }
                        }
+               }
+               if ( count( $batch ) ) {
+                       $this->doOperations( $tempRepo, $batch );
+                       $i += count( $batch );
                }
                $this->output( "$i done\n" );
 
@@ -118,6 +124,7 @@
                        $this->error( "Temp repo is not using the temp 
container.", 1 ); // die
                }
                $i = 0;
+               $batch = array(); // operation batch
                foreach ( $iterator as $file ) {
                        // Absolute sanity check for stashed files and file 
segments
                        $base = basename( $file );
@@ -127,17 +134,28 @@
                                continue;
                        }
                        if ( wfTimestamp( TS_UNIX, $tempRepo->getFileTimestamp( 
"$dir/$file" ) ) < $cutoff ) {
-                               $status = $tempRepo->quickPurge( "$dir/$file" );
-                               if ( !$status->isOK() ) {
-                                       $this->error( print_r( 
$status->getErrorsArray(), true ) );
-                               }
-                               if ( ( ++$i % 100 ) == 0 ) {
+                               $batch[] = array( 'op' => 'delete', 'src' => 
"$dir/$file" );
+                               if ( count( $batch ) >= $this->mBatchSize ) {
+                                       $this->doOperations( $tempRepo, $batch 
);
+                                       $i += count( $batch );
+                                       $batch = array();
                                        $this->output( "$i\n" );
                                }
                        }
                }
+               if ( count( $batch ) ) {
+                       $this->doOperations( $tempRepo, $batch );
+                       $i += count( $batch );
+               }
                $this->output( "$i done\n" );
        }
+
+       protected function doOperations( FileRepo $tempRepo, array $ops ) {
+               $status = $tempRepo->getBackend()->doQuickOperations( $ops );
+               if ( !$status->isOK() ) {
+                       $this->error( print_r( $status->getErrorsArray(), true 
) );
+               }
+       }
 }
 
 $maintClass = "UploadStashCleanup";

-- 
To view, visit https://gerrit.wikimedia.org/r/94453
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If3cfd333636f5b14c529629ce1ec408d396122a8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.23wmf2
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to