Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/94451
Change subject: Made cleanupUploadStash use batching for the last two loops
......................................................................
Made cleanupUploadStash use batching for the last two loops
Change-Id: If3cfd333636f5b14c529629ce1ec408d396122a8
---
M maintenance/cleanupUploadStash.php
1 file changed, 28 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/51/94451/1
diff --git a/maintenance/cleanupUploadStash.php
b/maintenance/cleanupUploadStash.php
index 2300694..d8fdae9 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, 'adviseStat' => 1 ) );
$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/94451
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If3cfd333636f5b14c529629ce1ec408d396122a8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits