Index: trunk/phase3/maintenance/purgeParserCache.php |
— | — | @@ -0,0 +1,43 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 5 | + |
| 6 | +class PurgeParserCache extends Maintenance { |
| 7 | + function __construct() { |
| 8 | + parent::__construct(); |
| 9 | + $this->addDescription( "Remove old objects from the parser cache. " . |
| 10 | + "This only works when the parser cache is in an SQL database." ); |
| 11 | + $this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true ); |
| 12 | + $this->addOption( 'age', |
| 13 | + 'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime '. |
| 14 | + 'has been consistent.', |
| 15 | + false, true ); |
| 16 | + } |
| 17 | + |
| 18 | + function execute() { |
| 19 | + $inputDate = $this->getOption( 'expiredate' ); |
| 20 | + $inputAge = $this->getOption( 'age' ); |
| 21 | + if ( $inputDate !== null ) { |
| 22 | + $date = wfTimestamp( TS_MW, strtotime( $inputDate ) ); |
| 23 | + } elseif ( $inputAge !== null ) { |
| 24 | + global $wgParserCacheExpireTime; |
| 25 | + $date = wfTimestamp( TS_MW, time() + $wgParserCacheExpireTime - intval( $inputAge ) ); |
| 26 | + } else { |
| 27 | + echo "Must specify either --expiredate or --age\n"; |
| 28 | + exit( 1 ); |
| 29 | + } |
| 30 | + |
| 31 | + $english = Language::factory( 'en' ); |
| 32 | + echo "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n"; |
| 33 | + |
| 34 | + $pc = wfGetParserCacheStorage(); |
| 35 | + $success = $pc->deleteObjectsExpiringBefore( $date ); |
| 36 | + if ( !$success ) { |
| 37 | + echo "Cannot purge this kind of parser cache.\n"; |
| 38 | + exit( 1 ); |
| 39 | + } |
| 40 | + echo "Done\n"; |
| 41 | + } |
| 42 | +} |
| 43 | +$maintClass = 'PurgeParserCache'; |
| 44 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/phase3/maintenance/purgeParserCache.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 45 | + native |
Index: trunk/phase3/includes/objectcache/BagOStuff.php |
— | — | @@ -91,6 +91,16 @@ |
92 | 92 | return array(); |
93 | 93 | } |
94 | 94 | |
| 95 | + /** |
| 96 | + * Delete all objects expiring before a certain date. |
| 97 | + * |
| 98 | + * @return true on success, false if unimplemented |
| 99 | + */ |
| 100 | + public function deleteObjectsExpiringBefore( $date ) { |
| 101 | + // stub |
| 102 | + return false; |
| 103 | + } |
| 104 | + |
95 | 105 | /* *** Emulated functions *** */ |
96 | 106 | |
97 | 107 | public function add( $key, $value, $exptime = 0 ) { |
Index: trunk/phase3/includes/objectcache/SqlBagOStuff.php |
— | — | @@ -305,21 +305,29 @@ |
306 | 306 | } |
307 | 307 | |
308 | 308 | public function expireAll() { |
| 309 | + $this->deleteObjectsExpiringBefore( wfTimestampNow() ); |
| 310 | + } |
| 311 | + |
| 312 | + /** |
| 313 | + * Delete objects from the database which expire before a certain date. |
| 314 | + */ |
| 315 | + public function deleteObjectsExpiringBefore( $timestamp ) { |
309 | 316 | $db = $this->getDB(); |
310 | | - $now = $db->timestamp(); |
| 317 | + $dbTimestamp = $db->timestamp( $timestamp ); |
311 | 318 | |
312 | 319 | try { |
313 | 320 | for ( $i = 0; $i < $this->shards; $i++ ) { |
314 | 321 | $db->begin(); |
315 | 322 | $db->delete( |
316 | 323 | $this->getTableByShard( $i ), |
317 | | - array( 'exptime < ' . $db->addQuotes( $now ) ), |
| 324 | + array( 'exptime < ' . $db->addQuotes( $dbTimestamp ) ), |
318 | 325 | __METHOD__ ); |
319 | 326 | $db->commit(); |
320 | 327 | } |
321 | 328 | } catch ( DBQueryError $e ) { |
322 | 329 | $this->handleWriteError( $e ); |
323 | 330 | } |
| 331 | + return true; |
324 | 332 | } |
325 | 333 | |
326 | 334 | public function deleteAll() { |
Index: trunk/phase3/includes/objectcache/MultiWriteBagOStuff.php |
— | — | @@ -89,9 +89,25 @@ |
90 | 90 | array_shift( $args ); |
91 | 91 | |
92 | 92 | foreach ( $this->caches as $cache ) { |
93 | | - $ret = $ret && call_user_func_array( array( $cache, $method ), $args ); |
| 93 | + if ( !call_user_func_array( array( $cache, $method ), $args ) ) { |
| 94 | + $ret = false; |
| 95 | + } |
94 | 96 | } |
95 | 97 | return $ret; |
96 | 98 | } |
97 | 99 | |
| 100 | + /** |
| 101 | + * Delete objects expiring before a certain date. |
| 102 | + * |
| 103 | + * Succeed if any of the child caches succeed. |
| 104 | + */ |
| 105 | + public function deleteObjectsExpiringBefore( $date ) { |
| 106 | + $ret = false; |
| 107 | + foreach ( $this->caches as $cache ) { |
| 108 | + if ( $cache->deleteObjectsExpiringBefore( $date ) ) { |
| 109 | + $ret = true; |
| 110 | + } |
| 111 | + } |
| 112 | + return $ret; |
| 113 | + } |
98 | 114 | } |