X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FpurgeParserCache.php;h=dcd6d13deb2a61086c6382ff89ad30e74cb4816e;hb=203f7aba8c4d3279cd9de7cb479f08b80fb1800a;hp=9970c1fd5d78da93efe7596215247f97268c1793;hpb=9f3dd6ceb2193056eea1b334bfca67d546594df1;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/purgeParserCache.php b/maintenance/purgeParserCache.php index 9970c1fd5d..dcd6d13deb 100644 --- a/maintenance/purgeParserCache.php +++ b/maintenance/purgeParserCache.php @@ -24,6 +24,8 @@ require __DIR__ . '/Maintenance.php'; +use MediaWiki\MediaWikiServices; + /** * Maintenance script to remove old objects from the parser cache. * @@ -32,6 +34,8 @@ require __DIR__ . '/Maintenance.php'; class PurgeParserCache extends Maintenance { public $lastProgress; + private $usleep = 0; + function __construct() { parent::__construct(); $this->addDescription( "Remove old objects from the parser cache. " . @@ -39,36 +43,44 @@ class PurgeParserCache extends Maintenance { $this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true ); $this->addOption( 'age', - 'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime ' . - 'has been consistent.', - false, true ); + 'Delete objects created more than this many seconds ago, assuming ' . + '$wgParserCacheExpireTime has remained consistent.', + false, + true ); + $this->addOption( 'msleep', 'Milliseconds to sleep between purge chunks', false, true ); } function execute() { + global $wgParserCacheExpireTime; + $inputDate = $this->getOption( 'expiredate' ); $inputAge = $this->getOption( 'age' ); if ( $inputDate !== null ) { $date = wfTimestamp( TS_MW, strtotime( $inputDate ) ); } elseif ( $inputAge !== null ) { - global $wgParserCacheExpireTime; $date = wfTimestamp( TS_MW, time() + $wgParserCacheExpireTime - intval( $inputAge ) ); } else { - $this->error( "Must specify either --expiredate or --age", 1 ); + $this->fatalError( "Must specify either --expiredate or --age" ); + return; } + $this->usleep = 1e3 * $this->getOption( 'msleep', 0 ); $english = Language::factory( 'en' ); - $this->output( "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n" ); + $this->output( "Deleting objects expiring before " . + $english->timeanddate( $date ) . "\n" ); - $pc = wfGetParserCacheStorage(); - $success = $pc->deleteObjectsExpiringBefore( $date, array( $this, 'showProgress' ) ); + $pc = MediaWikiServices::getInstance()->getParserCache()->getCacheStorage(); + $success = $pc->deleteObjectsExpiringBefore( $date, [ $this, 'showProgressAndWait' ] ); if ( !$success ) { - $this->error( "\nCannot purge this kind of parser cache.", 1 ); + $this->fatalError( "\nCannot purge this kind of parser cache." ); } - $this->showProgress( 100 ); + $this->showProgressAndWait( 100 ); $this->output( "\nDone\n" ); } - function showProgress( $percent ) { + public function showProgressAndWait( $percent ) { + usleep( $this->usleep ); // avoid lag; T150124 + $percentString = sprintf( "%.2f", $percent ); if ( $percentString === $this->lastProgress ) { return; @@ -81,5 +93,5 @@ class PurgeParserCache extends Maintenance { } } -$maintClass = 'PurgeParserCache'; +$maintClass = PurgeParserCache::class; require_once RUN_MAINTENANCE_IF_MAIN;