From f3a4fd56c020aa717dfd6eb69bdfe6a10ea35393 Mon Sep 17 00:00:00 2001 From: Lee Daniel Crocker Date: Fri, 2 May 2003 22:55:37 +0000 Subject: [PATCH] Completed several maintenance scripts for index rebuilding. --- maintenance/rebuildIndex.php | 46 ------- maintenance/rebuildall.php | 39 ++++++ .../{rebuildLinks.inc => rebuildlinks.inc} | 2 +- .../{rebuildLinks.php => rebuildlinks.php} | 19 +-- maintenance/rebuildrecentchanges.inc | 115 ++++++++++++++++++ maintenance/rebuildrecentchanges.php | 30 +++++ maintenance/rebuildtextindex.inc | 43 +++++++ maintenance/rebuildtextindex.php | 31 +++++ maintenance/tables.sql | 12 +- 9 files changed, 277 insertions(+), 60 deletions(-) delete mode 100644 maintenance/rebuildIndex.php create mode 100644 maintenance/rebuildall.php rename maintenance/{rebuildLinks.inc => rebuildlinks.inc} (99%) rename maintenance/{rebuildLinks.php => rebuildlinks.php} (53%) create mode 100644 maintenance/rebuildrecentchanges.inc create mode 100644 maintenance/rebuildrecentchanges.php create mode 100644 maintenance/rebuildtextindex.inc create mode 100644 maintenance/rebuildtextindex.php diff --git a/maintenance/rebuildIndex.php b/maintenance/rebuildIndex.php deleted file mode 100644 index 1bd085cff4..0000000000 --- a/maintenance/rebuildIndex.php +++ /dev/null @@ -1,46 +0,0 @@ -count} pages...\n"; -$n = 0; - -$sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur"; -$res = wfQuery($sql); -while( $s = wfFetchObject($res)) { - $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text ); - $u->doUpdate(); - if ( ( (++$n) % 500) == 0) { - echo "$n\n"; - } -} -wfFreeResult( $res ); - -#echo "Rebuild the index...\n"; -##$sql = "ALTER TABLE searchindex ADD FULLTEXT si_title (si_title), -## ADD FULLTEXT si_text (si_text)"; -#$res = wfQuery($sql); - -print "Done.\n"; -exit(); - -?> diff --git a/maintenance/rebuildall.php b/maintenance/rebuildall.php new file mode 100644 index 0000000000..9e64d193c3 --- /dev/null +++ b/maintenance/rebuildall.php @@ -0,0 +1,39 @@ + diff --git a/maintenance/rebuildLinks.inc b/maintenance/rebuildlinks.inc similarity index 99% rename from maintenance/rebuildLinks.inc rename to maintenance/rebuildlinks.inc index e98d6d7635..7dd3ddee50 100644 --- a/maintenance/rebuildLinks.inc +++ b/maintenance/rebuildlinks.inc @@ -2,7 +2,7 @@ # Functions for rebuilding the link tracking tables; must # be included within a script that also includes the Setup. -# See convertdb.php, for example. +# See rebuildlinks.php, for example. # function rebuildLinkTablesPass1() diff --git a/maintenance/rebuildLinks.php b/maintenance/rebuildlinks.php similarity index 53% rename from maintenance/rebuildLinks.php rename to maintenance/rebuildlinks.php index 2890507dfe..de756c1911 100644 --- a/maintenance/rebuildLinks.php +++ b/maintenance/rebuildlinks.php @@ -3,22 +3,27 @@ # Rebuild link tracking tables from scratch. This takes several # hours, depending on the database size and server configuration. -global $IP; +if ( ! is_readable( "../LocalSettings.php" ) ) { + print "A copy of your installation's LocalSettings.php\n" . + "must exist in the source directory.\n"; + exit(); +} + +$DP = "../includes"; include_once( "../LocalSettings.php" ); -include_once( "$IP/Setup.php" ); -include_once( "./rebuildLinks.inc" ); -include_once( "./rebuildRecentChanges.inc" ); +include_once( "../AdminSettings.php" ); + +include_once( "{$IP}/Setup.php" ); +include_once( "./rebuildlinks.inc" ); $wgTitle = Title::newFromText( "Rebuild links script" ); set_time_limit(0); -$wgDBuser = "wikiadmin"; +$wgDBuser = $wgDBadminuser; $wgDBpassword = $wgDBadminpassword; rebuildLinkTablesPass1(); rebuildLinkTablesPass2(); -rebuildRecentChangesTable(); - print "Done.\n"; exit(); diff --git a/maintenance/rebuildrecentchanges.inc b/maintenance/rebuildrecentchanges.inc new file mode 100644 index 0000000000..2d9c00933a --- /dev/null +++ b/maintenance/rebuildrecentchanges.inc @@ -0,0 +1,115 @@ +rc_timestamp; + + $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$ts}'"; + wfQuery( $sql ); +} + +function rebuildRecentChangesTablePass2() +{ + $ns = $id = $count = 0; + $title = $ct = ""; + + print( "Updating links...\n" ); + + $sql = "SELECT rc_namespace,rc_title,rc_timestamp FROM recentchanges " . + "ORDER BY rc_namespace,rc_title,rc_timestamp DESC"; + $res = wfQuery( $sql ); + + while ( $obj = wfFetchObject( $res ) ) { + if ( ! ( $ns == $obj->rc_namespace && + 0 == strcmp( $title, wfStrencode( $obj->rc_title ) ) ) ) { + + $ns = $obj->rc_namespace; + $title = wfStrencode( $obj->rc_title ); + + $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE " . + "cur_namespace={$ns} AND cur_title='{$title}'"; + $res2 = wfQuery( $sql ); + $obj2 = wfFetchObject( $res2 ); + + $id = $obj2->cur_id; + $ct = $obj2->cur_timestamp; + } + $sql = "SELECT old_id FROM old WHERE old_namespace={$ns} " . + "AND old_title='{$title}' AND old_timestamp < '" . + "{$obj->rc_timestamp}' ORDER BY old_timestamp DESC LIMIT 1"; + $res2 = wfQuery( $sql ); + + if ( 0 != wfNumRows( $res2 ) ) { + $obj2 = wfFetchObject( $res2 ); + + $sql = "UPDATE recentchanges SET rc_cur_id={$id},rc_cur_time=" . + "'{$ct}',rc_last_oldid={$obj2->old_id} WHERE " . + "rc_namespace={$ns} AND rc_title='{$title}' AND " . + "rc_timestamp='{$obj->rc_timestamp}'"; + wfQuery( $sql ); + } else { + $sql = "UPDATE recentchanges SET rc_cur_id={$id},rc_cur_time=" . + "'{$ct}' WHERE rc_namespace={$ns} AND rc_title='{$title}' " . + "AND rc_timestamp='{$obj->rc_timestamp}'"; + wfQuery( $sql ); + } + + if ( 0 == ( ++$count % 500 ) ) { + printf( "%d records processed.\n", $count ); + } + } +} + +?> diff --git a/maintenance/rebuildrecentchanges.php b/maintenance/rebuildrecentchanges.php new file mode 100644 index 0000000000..894353f179 --- /dev/null +++ b/maintenance/rebuildrecentchanges.php @@ -0,0 +1,30 @@ + diff --git a/maintenance/rebuildtextindex.inc b/maintenance/rebuildtextindex.inc new file mode 100644 index 0000000000..8d681c8fdf --- /dev/null +++ b/maintenance/rebuildtextindex.inc @@ -0,0 +1,43 @@ +count} pages...\n"; + $n = 0; + + $sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur"; + $res = wfQuery($sql); + + while( $s = wfFetchObject($res) ) { + $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text ); + $u->doUpdate(); + if ( ( (++$n) % 500) == 0) { echo "$n\n"; } + } + wfFreeResult( $res ); +} + +?> diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php new file mode 100644 index 0000000000..bbc5327d3b --- /dev/null +++ b/maintenance/rebuildtextindex.php @@ -0,0 +1,31 @@ + diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 09556af74d..9ca9f5e334 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -165,12 +165,12 @@ CREATE TABLE watchlist ( DROP TABLE IF EXISTS math; CREATE TABLE math ( - math_inputhash varchar(16) NOT NULL, - math_outputhash varchar(16) NOT NULL, - math_html_conservativeness tinyint(1) NOT NULL, - math_html text, - math_mathml text, - UNIQUE KEY math_inputhash (math_inputhash) + math_inputhash varchar(16) NOT NULL, + math_outputhash varchar(16) NOT NULL, + math_html_conservativeness tinyint(1) NOT NULL, + math_html text, + math_mathml text, + UNIQUE KEY math_inputhash (math_inputhash) ) TYPE=MyISAM; -- Table searchindex must be MyISAM for fulltext support -- 2.20.1