r79384 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79383‎ | r79384 | r79385 >
Date:23:32, 31 December 2010
Author:reedy
Status:resolved
Tags:
Comment:
Add repopuldateCodePaths maintenance script for bug 23720 (untested, will be doing so shortly)
Modified paths:
  • /trunk/extensions/CodeReview/repopulateCodePaths.php (added) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/repopulateCodePaths.php
@@ -0,0 +1,79 @@
 2+<?php
 3+$IP = getenv( 'MW_INSTALL_PATH' );
 4+if ( $IP === false ) {
 5+ $IP = dirname( __FILE__ ) . '/../..';
 6+}
 7+require( "$IP/maintenance/Maintenance.php" );
 8+
 9+class RepopulateCodePaths extends Maintenance {
 10+ public function __construct() {
 11+ parent::__construct();
 12+ $this->mDescription = "Rebuilds all code paths to support more efficient searching";
 13+ $this->addArg( 'repo', 'The name of the repo. Cannot be all.' );
 14+ $this->addArg( 'revisions', "The revisions to set status for. Format: start:end" );
 15+ }
 16+
 17+ public function execute() {
 18+ $repoName = $this->getArg( 0 );
 19+
 20+ if ( $repoName == "all" ) {
 21+ $this->error( "Cannot use the 'all' repo", true );
 22+ }
 23+
 24+ $repo = CodeRepository::newFromName( $repoName );
 25+ if ( !$repo ) {
 26+ $this->error( "Repo '{$repoName}' is not a valid Repository", true );
 27+ }
 28+
 29+ $revisions = $this->getArg( 1 );
 30+ if ( strpos( $revisions, ':' ) !== false ) {
 31+ $revisionVals = explode( ':', $revisions, 2 );
 32+ } else {
 33+ $this->error( "Invalid revision range", true );
 34+ }
 35+
 36+ $start = intval( $revisionVals[0] );
 37+ $end = intval( $revisionVals[1] );
 38+
 39+ $revisions = range( $start, $end );
 40+
 41+ $dbr = wfGetDB( DB_SLAVE );
 42+
 43+ $res = $dbr->select( 'code_paths', '*', array( 'cp_rev_id' => $revisions, 'cp_repo_id' => $repo->getId() ),
 44+ __METHOD__ );
 45+
 46+ $data = array();
 47+ foreach ( $res as $row ) {
 48+ $this->output( "r{$row->cp_rev_id}\n" );
 49+
 50+ $data[] = array(
 51+ 'cp_repo_id' => $repo->getId(),
 52+ 'cp_rev_id' => $row->cp_rev_id,
 53+ 'cp_path' => CodeRevision::getPathFragments( array( $row->cp_path ) ),
 54+ 'cp_action' => $row->cp_action
 55+ );
 56+ }
 57+
 58+ $dbw = wfGetDB( DB_MASTER );
 59+ $dbw->begin();
 60+ $this->output( "Commiting paths...\n" );
 61+ $this->insertChunks( $dbw, 'code_paths', $data, __METHOD__, array( 'IGNORE' ) );
 62+ $dbw->commit();
 63+
 64+ $this->output( "Done!\n" );
 65+ }
 66+
 67+ private static function insertChunks( $db, $table, $data, $method = __METHOD__, $options = array() ) {
 68+ $chunkSize = 100;
 69+ for ( $i = 0; $i < count( $data ); $i += $chunkSize ) {
 70+ $db->insert( $table,
 71+ array_slice( $data, $i, $chunkSize ),
 72+ $method,
 73+ $options
 74+ );
 75+ }
 76+ }
 77+}
 78+
 79+$maintClass = "RepopulateCodePaths";
 80+require_once( DO_MAINTENANCE );
Property changes on: trunk/extensions/CodeReview/repopulateCodePaths.php
___________________________________________________________________
Added: svn:eol-style
181 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r79390More refactoring and fixing for bug 23720reedy00:03, 1 January 2011
r79401Minor extra bit for bug 23720, remove performance restrictionreedy01:12, 1 January 2011
r81038(bug 23720) CodeReview doesn't show ancient revisions for a path...reedy17:27, 26 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79379*(bug 23720) CodeReview doesn't show ancient revisions for a path...reedy22:55, 31 December 2010
r79381More for bug 23720....reedy23:02, 31 December 2010

Status & tagging log