r100488 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100487‎ | r100488 | r100489 >
Date:02:15, 22 October 2011
Author:aaron
Status:ok
Tags:
Comment:
MFT r99187,r99193 - 'Added script to manually clear out old data (per $wgCUDMaxAge)'
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/CheckUser/CheckUser.hooks.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/CheckUser/maintenance (added) (history)
  • /branches/wmf/1.18wmf1/extensions/CheckUser/maintenance/purgeOldData.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/CheckUser/maintenance/purgeOldData.php
@@ -0,0 +1,69 @@
 2+<?php
 3+if ( getenv( 'MW_INSTALL_PATH' ) ) {
 4+ $IP = getenv( 'MW_INSTALL_PATH' );
 5+} else {
 6+ $IP = dirname(__FILE__).'/../../..';
 7+}
 8+require_once( "$IP/maintenance/Maintenance.php" );
 9+
 10+class PurgeOldIPAddressData extends Maintenance {
 11+ public function __construct() {
 12+ parent::__construct();
 13+ $this->mDescription = "Purge expired rows in CheckUser and RecentChanges";
 14+ $this->setBatchSize( 200 );
 15+ }
 16+
 17+ public function execute() {
 18+ global $wgCUDMaxAge, $wgRCMaxAge, $wgPutIPinRC;
 19+
 20+ $this->output( "Purging data from cu_changes..." );
 21+ $count = $this->prune( 'cu_changes', 'cuc_timestamp', $wgCUDMaxAge );
 22+ $this->output( $count . " rows.\n" );
 23+
 24+ if ( $wgPutIPinRC ) {
 25+ $this->output( "Purging data from recentchanges..." );
 26+ $count = $this->prune( 'recentchanges', 'rc_timestamp', $wgRCMaxAge );
 27+ $this->output( $count . " rows.\n" );
 28+ }
 29+
 30+ $this->output( "Done.\n" );
 31+ }
 32+
 33+ protected function prune( $table, $ts_column, $maxAge ) {
 34+ $dbw = wfGetDB( DB_MASTER );
 35+
 36+ $expiredCond = "$ts_column < " . $dbw->addQuotes( $dbw->timestamp( time() - $maxAge ) );
 37+
 38+ $count = 0;
 39+ while ( true ) {
 40+ // Get the first $this->mBatchSize (or less) items
 41+ $res = $dbw->select( $table, $ts_column,
 42+ $expiredCond,
 43+ __METHOD__,
 44+ array( 'ORDER BY' => "$ts_column ASC", 'LIMIT' => $this->mBatchSize )
 45+ );
 46+ if ( !$res->numRows() ) {
 47+ break; // all cleared
 48+ }
 49+ // Record the start and end timestamp for the set
 50+ $blockStart = $res->fetchObject()->$ts_column;
 51+ $res->seek( $res->numRows() - 1 );
 52+ $blockEnd = $res->fetchObject()->$ts_column;
 53+ $res->free();
 54+
 55+ // Do the actual delete...
 56+ $dbw->begin();
 57+ $dbw->delete( $table,
 58+ array( "$ts_column BETWEEN $blockStart AND $blockEnd" ), __METHOD__ );
 59+ $count += $dbw->affectedRows();
 60+ $dbw->commit();
 61+
 62+ wfWaitForSlaves();
 63+ }
 64+
 65+ return $count;
 66+ }
 67+}
 68+
 69+$maintClass = "PurgeOldIPAddressData";
 70+require_once( RUN_MAINTENANCE_IF_MAIN );
Property changes on: branches/wmf/1.18wmf1/extensions/CheckUser/maintenance/purgeOldData.php
___________________________________________________________________
Added: svn:eol-style
171 + native
Property changes on: branches/wmf/1.18wmf1/extensions/CheckUser/maintenance
___________________________________________________________________
Added: bugtraq:number
272 + true
Index: branches/wmf/1.18wmf1/extensions/CheckUser/CheckUser.hooks.php
@@ -60,11 +60,8 @@
6161
6262 # Every 100th edit, prune the checkuser changes table.
6363 if ( 0 == mt_rand( 0, 99 ) ) {
64 - # Periodically flush old entries from the recentchanges table.
65 - $cutoff = $dbw->timestamp( time() - $wgCUDMaxAge );
66 - $recentchanges = $dbw->tableName( 'cu_changes' );
67 - $sql = "DELETE FROM $recentchanges WHERE cuc_timestamp < '{$cutoff}'";
68 - $dbw->query( $sql, __METHOD__ );
 64+ $encCutoff = $dbw->addQuotes( $dbw->timestamp( time() - $wgCUDMaxAge ) );
 65+ $dbw->delete( 'cu_changes', array( "cuc_timestamp < $encCutoff" ), __METHOD__ );
6966 }
7067
7168 return true;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99187* Added script to manually clear out old data (per $wgCUDMaxAge)...aaron03:28, 7 October 2011
r99193FU r99187:...aaron04:52, 7 October 2011

Status & tagging log