r52341 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52340‎ | r52341 | r52342 >
Date:03:08, 24 June 2009
Author:demon
Status:deferred
Tags:
Comment:
(bug 19371) Bugs after Maintenance script rewrite
Modified paths:
  • /branches/maintenance-work/maintenance/benchmarkPurge.php (modified) (history)
  • /branches/maintenance-work/maintenance/changePassword.php (modified) (history)
  • /branches/maintenance-work/maintenance/checkImages.php (modified) (history)
  • /branches/maintenance-work/maintenance/nextJobDB.php (modified) (history)
  • /branches/maintenance-work/maintenance/purgeOldText.php (modified) (history)
  • /branches/maintenance-work/maintenance/rebuildtextindex.php (modified) (history)
  • /branches/maintenance-work/maintenance/renameDbPrefix.php (modified) (history)
  • /branches/maintenance-work/maintenance/stats.php (modified) (history)
  • /branches/maintenance-work/maintenance/updateArticleCount.php (modified) (history)

Diff [purge]

Index: branches/maintenance-work/maintenance/stats.php
@@ -26,9 +26,9 @@
2727 $this->error( "You either have no stats or memcached isn't running. Aborting.\n", true );
2828 }
2929 $this->output( "Requests\n" );
30 - $this->output( sprintf( "with session: %-10d %6.2f%%\n", $session, $session/$total*100 );
31 - $this->output( sprintf( "without session: %-10d %6.2f%%\n", $noSession, $noSession/$total*100 );
32 - $this->output( sprintf( "total: %-10d %6.2f%%\n", $total, 100 );
 30+ $this->output( sprintf( "with session: %-10d %6.2f%%\n", $session, $session/$total*100 ) );
 31+ $this->output( sprintf( "without session: %-10d %6.2f%%\n", $noSession, $noSession/$total*100 ) );
 32+ $this->output( sprintf( "total: %-10d %6.2f%%\n", $total, 100 ) );
3333
3434
3535 $this->output( "\nParser cache\n" );
@@ -59,9 +59,9 @@
6060 $uncacheable = intval($wgMemc->get(wfMemcKey('stats','diff_uncacheable')));
6161 $total = $hits + $misses + $uncacheable;
6262 $this->output("\nDiff cache\n");
63 - $this->output( sprintf( "hits: %-10d %6.2f%%\n", $hits, $hits/$total*100 );
64 - $this->output( sprintf( "misses: %-10d %6.2f%%\n", $misses, $misses/$total*100 );
65 - $this->output( sprintf( "uncacheable: %-10d %6.2f%%\n", $uncacheable, $uncacheable/$total*100 );
 63+ $this->output( sprintf( "hits: %-10d %6.2f%%\n", $hits, $hits/$total*100 ) );
 64+ $this->output( sprintf( "misses: %-10d %6.2f%%\n", $misses, $misses/$total*100 ) );
 65+ $this->output( sprintf( "uncacheable: %-10d %6.2f%%\n", $uncacheable, $uncacheable/$total*100 ) );
6666 }
6767 }
6868
Index: branches/maintenance-work/maintenance/updateArticleCount.php
@@ -15,14 +15,14 @@
1616 private $namespaces;
1717
1818 public function __construct() {
19 - global $wgContentNamespaces;
2019 parent::__construct();
2120 $this->mDescription = "Count of the number of articles and update the site statistics table";
2221 $this->addParam( 'update', 'Update the site_stats table with the new count' );
23 - $this->namespaces = $wgContentNamespaces;
2422 }
2523
2624 public function execute() {
 25+ global $wgContentNamespaces;
 26+ $this->namespaces = $wgContentNamespaces;
2727 $this->output( "Counting articles..." );
2828 $result = $this->count();
2929
Index: branches/maintenance-work/maintenance/changePassword.php
@@ -17,7 +17,7 @@
1818 parent::__construct();
1919 $this->addParam( "user", "The username to operate on", true, true );
2020 $this->addParam( "password", "The password to use", true, true );
21 - $this->mDescription = "Change a user's password."
 21+ $this->mDescription = "Change a user's password";
2222 }
2323
2424 public function execute() {
Index: branches/maintenance-work/maintenance/purgeOldText.php
@@ -12,7 +12,7 @@
1313 public function __construct() {
1414 parent::__construct();
1515 $this->mDescription = "Purge old text records from the database";
16 - $this->addOption( 'purge', 'Performs the deletion' );
 16+ $this->addParam( 'purge', 'Performs the deletion' );
1717 }
1818
1919 public function execute() {
Index: branches/maintenance-work/maintenance/checkImages.php
@@ -28,7 +28,7 @@
2929 $file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
3030 $path = $file->getPath();
3131 if ( !$path ) {
32 - $this->output( "{$row->img_name}: not locally accessible\n";
 32+ $this->output( "{$row->img_name}: not locally accessible\n" );
3333 continue;
3434 }
3535 $stat = @stat( $file->getPath() );
Index: branches/maintenance-work/maintenance/nextJobDB.php
@@ -16,16 +16,16 @@
1717 }
1818 public function execute() {
1919 global $wgMemc;
20 - $type = $this->getParam( 'type', false );
 20+ $type = $this->getOption( 'type', false );
2121 $mckey = $type === false
2222 ? "jobqueue:dbs"
2323 : "jobqueue:dbs:$type";
24 - $pendingDBs = $wgMemcKey->get( $mckey );
 24+ $pendingDBs = $wgMemc->get( $mckey );
2525
2626 # If we didn't get it from the cache
2727 if( !$pendingDBs ) {
2828 $pendingDBs = $this->getPendingDbs( $type );
29 - $wgMemc->get( $mckey, $pendingDBs, 300 )
 29+ $wgMemc->get( $mckey, $pendingDBs, 300 );
3030 }
3131 # If we've got a pending job in a db, display it.
3232 if ( $pendingDBs ) {
@@ -39,6 +39,7 @@
4040 * @return array
4141 */
4242 private function getPendingDbs( $type ) {
 43+ global $wgLocalDatabases;
4344 $pendingDBs = array();
4445 # Cross-reference DBs by master DB server
4546 $dbsByMaster = array();
Index: branches/maintenance-work/maintenance/renameDbPrefix.php
@@ -38,7 +38,7 @@
3939 $this->error( "Invalid prefix!\n", true );
4040 }
4141 if( $old === $new ) {
42 - $this->( "Same prefix. Nothing to rename!\n", true );
 42+ $this->output( "Same prefix. Nothing to rename!\n", true );
4343 }
4444
4545 $this->output( "Renaming DB prefix for tables of $wgDBname from '$old' to '$new'\n" );
Index: branches/maintenance-work/maintenance/benchmarkPurge.php
@@ -12,7 +12,7 @@
1313
1414 public function __construct() {
1515 parent::__construct();
16 - $this->addParams( "count", "How many URLs to feed to Squid for purging", false, true );
 16+ $this->addParam( "count", "How many URLs to feed to Squid for purging", false, true );
1717 $this->mDescription = "Benchmark the Squid purge functions.";
1818 }
1919
Index: branches/maintenance-work/maintenance/rebuildtextindex.php
@@ -11,23 +11,82 @@
1212 * @ingroup Maintenance
1313 */
1414
15 -/** */
16 -require_once( "commandLine.inc" );
17 -require_once( "rebuildtextindex.inc" );
 15+require_once( "Maintenance.php" );
1816
19 -$database = wfGetDB( DB_MASTER );
20 -if( !$database instanceof DatabaseMysql ) {
21 - print "This script is only for MySQL.\n";
22 - exit(1);
23 -}
 17+class RebuildTextIndex extends Maintenance {
2418
25 -$wgTitle = Title::newFromText( "Rebuild text index script" );
 19+ const RTI_CHUNK_SIZE = 500;
2620
27 -dropTextIndex( $database );
28 -rebuildTextIndex( $database );
29 -createTextIndex( $database );
 21+ public function __construct() {
 22+ parent::__construct();
 23+ $this->mDescription = "Rebuild search index table from scratch";
 24+ }
3025
31 -print "Done.\n";
32 -exit(0);
 26+ public function execute() {
 27+ global $wgTitle;
 28+
 29+ // Only do this for MySQL
 30+ $database = wfGetDB( DB_MASTER );
 31+ if( !$database instanceof DatabaseMysql ) {
 32+ $this->error( "This script is only for MySQL.\n", true );
 33+ }
3334
 35+ $wgTitle = Title::newFromText( "Rebuild text index script" );
 36+
 37+ $this->dropTextIndex( $database );
 38+ $this->rebuildTextIndex( $database );
 39+ $this->createTextIndex( $database );
 40+
 41+ $this->output( "Done.\n" );
 42+ }
 43+
 44+ private function dropTextIndex( &$database ) {
 45+ $searchindex = $database->tableName( 'searchindex' );
 46+ if ( $database->indexExists( "searchindex", "si_title" ) ) {
 47+ $this->output( "Dropping index...\n" );
 48+ $sql = "ALTER TABLE $searchindex DROP INDEX si_title, DROP INDEX si_text";
 49+ $database->query($sql, "dropTextIndex" );
 50+ }
 51+ }
3452
 53+ private function createTextIndex( &$database ) {
 54+ $searchindex = $database->tableName( 'searchindex' );
 55+ $this->output( "\nRebuild the index...\n" );
 56+ $sql = "ALTER TABLE $searchindex ADD FULLTEXT si_title (si_title), " .
 57+ "ADD FULLTEXT si_text (si_text)";
 58+ $database->query($sql, "createTextIndex" );
 59+ }
 60+
 61+ private function rebuildTextIndex( &$database ) {
 62+ list ($page, $revision, $text, $searchindex) = $database->tableNamesN( 'page', 'revision', 'text', 'searchindex' );
 63+
 64+ $sql = "SELECT MAX(page_id) AS count FROM $page";
 65+ $res = $database->query($sql, "rebuildTextIndex" );
 66+ $s = $database->fetchObject($res);
 67+ $count = $s->count;
 68+ $this->output( "Rebuilding index fields for {$count} pages...\n" );
 69+ $n = 0;
 70+
 71+ while ( $n < $count ) {
 72+ $this->output( $n . "\n" );
 73+ $end = $n + self::RTI_CHUNK_SIZE - 1;
 74+ $sql = "SELECT page_id, page_namespace, page_title, old_flags, old_text
 75+ FROM $page, $revision, $text
 76+ WHERE page_id BETWEEN $n AND $end
 77+ AND page_latest=rev_id
 78+ AND rev_text_id=old_id";
 79+ $res = $database->query($sql, "rebuildTextIndex" );
 80+
 81+ while( $s = $database->fetchObject($res) ) {
 82+ $revtext = Revision::getRevisionText( $s );
 83+ $u = new SearchUpdate( $s->page_id, $s->page_title, $revtext );
 84+ $u->doUpdate();
 85+ }
 86+ $database->freeResult( $res );
 87+ $n += self::RTI_CHUNK_SIZE;
 88+ }
 89+ }
 90+}
 91+
 92+$maintClass = "RebuildTextIndex";
 93+require_once( DO_MAINTENANCE );

Status & tagging log