From 2aee9e3b16a1e416a194d6d4aba3c8940776dc6b Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 14 May 2009 23:06:53 +0000 Subject: [PATCH] Populate log_search during update.php run and store an update status row when we're done. --- maintenance/populateLogSearch.inc | 80 +++++++++++++++++++++++++++++++ maintenance/populateLogSearch.php | 57 +--------------------- maintenance/updaters.inc | 16 +++++++ 3 files changed, 97 insertions(+), 56 deletions(-) create mode 100644 maintenance/populateLogSearch.inc diff --git a/maintenance/populateLogSearch.inc b/maintenance/populateLogSearch.inc new file mode 100644 index 0000000000..1f0a2bb858 --- /dev/null +++ b/maintenance/populateLogSearch.inc @@ -0,0 +1,80 @@ +selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ ); + if( !$start ) { + die("Nothing to do.\n"); + } + $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ ); + + # Do remaining chunk + $end += LOG_SEARCH_BATCH_SIZE - 1; + $blockStart = $start; + $blockEnd = $start + LOG_SEARCH_BATCH_SIZE - 1; + while( $blockEnd <= $end ) { + echo "...doing log_id from $blockStart to $blockEnd\n"; + $cond = "log_id BETWEEN $blockStart AND $blockEnd"; + $res = $db->select( 'logging', '*', $cond, __FUNCTION__ ); + $batch = array(); + while( $row = $db->fetchObject( $res ) ) { + // RevisionDelete logs - revisions + if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) { + $params = LogPage::extractParams( $row->log_params ); + // Param format: [ ] + if( count($params) >= 2 ) { + $field = RevisionDeleter::getRelationType($params[0]); + // B/C, the params may start with a title key + if( $field == null ) { + array_shift($params); + $field = RevisionDeleter::getRelationType($params[0]); + } + if( $field == null ) { + echo "Invalid param type for $row->log_id"; + continue; // skip this row + } + $items = explode(',',$params[1]); + $log = new LogPage( $row->log_type ); + $log->addRelations( $field, $items, $row->log_id ); + } + // RevisionDelete logs - log events + } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) { + $params = LogPage::extractParams( $row->log_params ); + // Param format: [ ] + if( count($params) >= 1 ) { + $items = explode(',',$params[0]); + $log = new LogPage( $row->log_type ); + $log->addRelations( 'log_id', $items, $row->log_id ); + } + } + } + $blockStart += LOG_SEARCH_BATCH_SIZE - 1; + $blockEnd += LOG_SEARCH_BATCH_SIZE - 1; + wfWaitForSlaves( 5 ); + } + if( $db->insert( + 'updatelog', + array( 'ul_key' => 'populate log_search' ), + __FUNCTION__, + 'IGNORE' + ) + ) { + wfOut( "log_search population complete.\n" ); + return true; + } else { + wfOut( "Could not insert log_search population row.\n" ); + return false; + } +} diff --git a/maintenance/populateLogSearch.php b/maintenance/populateLogSearch.php index 6205f7e2fc..3679f7efee 100644 --- a/maintenance/populateLogSearch.php +++ b/maintenance/populateLogSearch.php @@ -9,9 +9,8 @@ * @ingroup Maintenance */ -define( 'BATCH_SIZE', 100 ); - require_once 'commandLine.inc'; +require_once 'populateLogSearch.inc'; $db =& wfGetDB( DB_MASTER ); if ( !$db->tableExists( 'log_search' ) ) { @@ -20,57 +19,3 @@ if ( !$db->tableExists( 'log_search' ) ) { } migrate_log_params( $db ); - -function migrate_log_params( $db ) { - $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ ); - if( !$start ) { - die("Nothing to do.\n"); - } - $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ ); - - # Do remaining chunk - $end += BATCH_SIZE - 1; - $blockStart = $start; - $blockEnd = $start + BATCH_SIZE - 1; - while( $blockEnd <= $end ) { - echo "...doing log_id from $blockStart to $blockEnd\n"; - $cond = "log_id BETWEEN $blockStart AND $blockEnd"; - $res = $db->select( 'logging', '*', $cond, __FUNCTION__ ); - $batch = array(); - while( $row = $db->fetchObject( $res ) ) { - // RevisionDelete logs - revisions - if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) { - $params = LogPage::extractParams( $row->log_params ); - // Param format: [ ] - if( count($params) >= 2 ) { - $field = RevisionDeleter::getRelationType($params[0]); - // B/C, the params may start with a title key - if( $field == null ) { - array_shift($params); - $field = RevisionDeleter::getRelationType($params[0]); - } - if( $field == null ) { - echo "Invalid param type for $row->log_id"; - continue; // skip this row - } - $items = explode(',',$params[1]); - $log = new LogPage( $row->log_type ); - $log->addRelations( $field, $items, $row->log_id ); - } - // RevisionDelete logs - log events - } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) { - $params = LogPage::extractParams( $row->log_params ); - // Param format: [ ] - if( count($params) >= 1 ) { - $items = explode(',',$params[0]); - $log = new LogPage( $row->log_type ); - $log->addRelations( 'log_id', $items, $row->log_id ); - } - } - } - $blockStart += BATCH_SIZE - 1; - $blockEnd += BATCH_SIZE - 1; - wfWaitForSlaves( 5 ); - } - echo "...Done!\n"; -} diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 72e510f3cf..20b19f3e3d 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -158,6 +158,7 @@ $wgUpdates = array( array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ), array( 'add_table', 'user_properties', 'patch-user_properties.sql' ), array( 'add_table', 'log_search', 'patch-log_search.sql' ), + array( 'do_log_search_population' ), ), 'sqlite' => array( @@ -1305,6 +1306,21 @@ function do_unique_pl_tl_il() { } } +function do_log_search_population() { + if( update_row_exists( 'populate log_search' ) ) { + wfOut( "...log_search table already populated.\n" ); + return; + } + require_once( 'populateLogSearch.inc' ); + wfOut( +"Populating log_search table, printing progress markers. For large\n" . +"databases, you may want to hit Ctrl-C and do this manually with\n" . +"maintenance/populateLogSearch.php.\n" ); + $db =& wfGetDB( DB_MASTER ); + migrate_log_params( $db ); + wfOut( "Done populating log_search table.\n" ); +} + /*********************************************************************** * Start PG crap * TODO: merge with above -- 2.20.1