X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FcleanupUploadStash.php;h=24b63a8bab9ec8fce9050fc325f02548e1d53d55;hb=5a77286a1e32f4fd784b5c2985f149fe39b45073;hp=bc43c6760be3aec9399bfe6185c7f5dfacaaf189;hpb=a36b3c44ed0a950efbd4e01557db6014701d71e6;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/cleanupUploadStash.php b/maintenance/cleanupUploadStash.php index bc43c6760b..24b63a8bab 100644 --- a/maintenance/cleanupUploadStash.php +++ b/maintenance/cleanupUploadStash.php @@ -38,6 +38,7 @@ class UploadStashCleanup extends Maintenance { public function __construct() { parent::__construct(); $this->mDescription = "Clean up abandoned files in temporary uploaded file stash"; + $this->setBatchSize( 50 ); } public function execute() { @@ -94,20 +95,25 @@ class UploadStashCleanup extends Maintenance { // Delete all the corresponding thumbnails... $dir = $tempRepo->getZonePath( 'thumb' ); - $iterator = $tempRepo->getBackend()->getFileList( array( 'dir' => $dir ) ); + $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" ); // Apparently lots of stash files are not registered in the DB... @@ -118,26 +124,31 @@ class UploadStashCleanup extends Maintenance { $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 ); - // @TODO: why are there thumbnails stored in here? - if ( !preg_match( '#(^\d{14}!|\.\d+\.\w+\.\d+$|-\w{12}\.\w{6}\.\d+\.)#', $base ) ) { - $this->output( "Skipped non-stash $file\n" ); - 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";