r32937 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32936‎ | r32937 | r32938 >
Date:01:09, 8 April 2008
Author:aaron
Status:old
Tags:
Comment:
Add a script to populate rev_parent_id
Modified paths:
  • /trunk/phase3/maintenance/populateParentId.php (added) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -135,6 +135,7 @@
136136 array( 'add_table', 'updatelog', 'patch-updatelog.sql' ),
137137 array( 'add_table', 'category', 'patch-category.sql' ),
138138 array( 'do_category_population' ),
 139+ array( 'do_populate_parent_id' ),
139140 );
140141
141142
@@ -1151,6 +1152,14 @@
11521153 echo "Done populating category table.\n";
11531154 }
11541155
 1156+function do_populate_parent_id() {
 1157+ if( update_row_exists( 'populate rev_parent_id' ) ) {
 1158+ echo "...rev_parent_id column already populated.\n";
 1159+ return;
 1160+ }
 1161+ require_once( 'populateParentId.inc' );
 1162+}
 1163+
11551164 function
11561165 pg_describe_table($table)
11571166 {
Index: trunk/phase3/maintenance/populateParentId.php
@@ -0,0 +1,62 @@
 2+<?php
 3+
 4+/*
 5+ * Makes the required database updates for rev_parent_id
 6+ * to be of any use. It can be used for some simple tracking
 7+ * and to find new page edits by users.
 8+ */
 9+
 10+define( 'BATCH_SIZE', 100 );
 11+
 12+require_once 'commandLine.inc';
 13+
 14+$db =& wfGetDB( DB_MASTER );
 15+if ( !$db->tableExists( 'revision' ) ) {
 16+ echo "revision table does not exist\n";
 17+ exit( 1 );
 18+}
 19+
 20+populate_rev_parent_id( $db );
 21+
 22+function populate_rev_parent_id( $db ) {
 23+ echo "Populating rev_parent_id column\n";
 24+ $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
 25+ $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ );
 26+ $blockStart = $start;
 27+ $blockEnd = $start + BATCH_SIZE - 1;
 28+ while( $blockEnd <= $end ) {
 29+ $cond = "rev_id BETWEEN $blockStart AND $blockEnd";
 30+ $res = $db->select( 'revision', array('rev_id', 'rev_page'), $cond, __FUNCTION__ );
 31+ # Go through and update rev_parent_id from these rows.
 32+ # Assume that the previous revision of the title was
 33+ # the original previous revision of the title when the
 34+ # edit was made...
 35+ while( $row = $db->fetchObject( $res ) ) {
 36+ $previousID = $db->selectField( 'revision', 'rev_id',
 37+ array( 'rev_page' => $row->rev_page, 'rev_id < ' . $row->rev_id ),
 38+ __FUNCTION__,
 39+ array( 'ORDER BY' => 'rev_id DESC' ) );
 40+ # Update the row...
 41+ $db->update( 'revision',
 42+ array( 'rev_parent_id' => intval($previousID) ),
 43+ array( 'rev_page' => $row->rev_page, 'rev_id' => $row->rev_id ),
 44+ __FUNCTION__ );
 45+ }
 46+ $blockStart += BATCH_SIZE;
 47+ $blockEnd += BATCH_SIZE;
 48+ wfWaitForSlaves( 5 );
 49+ }
 50+ $logged = $db->insert( 'updatelog',
 51+ array( 'ul_key' => 'populate rev_parent_id' ),
 52+ __FUNCTION__,
 53+ 'IGNORE' );
 54+ if( $logged ) {
 55+ echo "rev_parent_id population complete\n";
 56+ return true;
 57+ } else {
 58+ echo "Could not insert rev_parent_id population row.\n";
 59+ return false;
 60+ }
 61+}
 62+
 63+
Property changes on: trunk/phase3/maintenance/populateParentId.php
___________________________________________________________________
Added: svn:eol-style
164 + native

Status & tagging log