From f7afe42713a53452ac808ea337eb8390414b47eb Mon Sep 17 00:00:00 2001 From: Bill Pirkle Date: Fri, 15 Mar 2019 10:59:41 -0500 Subject: [PATCH] Remove many references to db fields being retired as part of MCR Schema Migration Remove many references to database fields rev_text_id and ar_text_id, which are being retired as part of MCR Schema Migration. Some references remain, and will be removed under other patchsets or other tasks. Bug: T198341 Change-Id: Id044b8dcd7c9d09d5d6037eb732f6a105933f516 --- includes/api/ApiQueryUserContribs.php | 1 - includes/cache/MessageCache.php | 31 ++++++------ maintenance/Maintenance.php | 48 +++++++++++++------ maintenance/populateContentTables.php | 5 ++ maintenance/rebuildtextindex.php | 4 +- tests/phpunit/includes/ActorMigrationTest.php | 2 - 6 files changed, 57 insertions(+), 34 deletions(-) diff --git a/includes/api/ApiQueryUserContribs.php b/includes/api/ApiQueryUserContribs.php index 7e548abce5..5b178b7478 100644 --- a/includes/api/ApiQueryUserContribs.php +++ b/includes/api/ApiQueryUserContribs.php @@ -525,7 +525,6 @@ class ApiQueryUserContribs extends ApiQueryBase { if ( $this->fld_ids ) { $vals['pageid'] = (int)$row->rev_page; $vals['revid'] = (int)$row->rev_id; - // $vals['textid'] = (int)$row->rev_text_id; // todo: Should this field be exposed? if ( !is_null( $row->rev_parent_id ) ) { $vals['parentid'] = (int)$row->rev_parent_id; diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index b669fcd492..e78dfa16bb 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -48,7 +48,7 @@ class MessageCache { /** * Process cache of loaded messages that are defined in MediaWiki namespace * - * @var MapCacheLRU Map of (language code => key => " " or "!TOO BIG") + * @var MapCacheLRU Map of (language code => key => " " or "!TOO BIG" or "!ERROR") */ protected $cache; @@ -535,27 +535,30 @@ class MessageCache { } // Set the text for small software-defined messages in the main cache map + $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $revQuery = $revisionStore->getQueryInfo( [ 'page', 'user' ] ); $res = $dbr->select( - [ 'page', 'revision', 'text' ], - [ 'page_title', 'page_latest', 'old_id', 'old_text', 'old_flags' ], + $revQuery['tables'], + $revQuery['fields'], array_merge( $conds, [ 'page_len <= ' . intval( $wgMaxMsgCacheEntrySize ) ] ), __METHOD__ . "($code)-small", [], - [ - 'revision' => [ 'JOIN', 'page_latest=rev_id' ], - 'text' => [ 'JOIN', 'rev_text_id=old_id' ], - ] + $revQuery['joins'] ); foreach ( $res as $row ) { $name = $this->contLang->lcfirst( $row->page_title ); // Include entries/stubs for all keys in $mostused in adaptive mode if ( $wgAdaptiveMessageCache || $this->isMainCacheable( $name, $overridable ) ) { - $text = Revision::getRevisionText( $row ); - if ( $text === false ) { - // Failed to fetch data; possible ES errors? - // Store a marker to fetch on-demand as a workaround... - // TODO Use a differnt marker - $entry = '!TOO BIG'; + try { + $rev = $revisionStore->newRevisionFromRow( $row ); + $content = $rev->getContent( MediaWiki\Revision\SlotRecord::MAIN ); + $text = $this->getMessageTextFromContent( $content ); + } catch ( Exception $ex ) { + $text = false; + } + + if ( !is_string( $text ) ) { + $entry = '!ERROR'; wfDebugLog( 'MessageCache', __METHOD__ @@ -1049,7 +1052,7 @@ class MessageCache { if ( $entry !== null ) { // Message page exists as an override of a software messages if ( substr( $entry, 0, 1 ) === ' ' ) { - // The message exists and is not '!TOO BIG' + // The message exists and is not '!TOO BIG' or '!ERROR' return (string)substr( $entry, 1 ); } elseif ( $entry === '!NONEXISTENT' ) { // The text might be '-' or missing due to some data loss diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index b638b42dff..ad748f330a 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1281,27 +1281,45 @@ abstract class Maintenance { * @author Rob Church */ public function purgeRedundantText( $delete = true ) { + global $wgMultiContentRevisionSchemaMigrationStage; + # Data should come off the master, wrapped in a transaction $dbw = $this->getDB( DB_MASTER ); $this->beginTransaction( $dbw, __METHOD__ ); - # Get "active" text records from the revisions table - $cur = []; - $this->output( 'Searching for active text records in revisions table...' ); - $res = $dbw->select( 'revision', 'rev_text_id', [], __METHOD__, [ 'DISTINCT' ] ); - foreach ( $res as $row ) { - $cur[] = $row->rev_text_id; - } - $this->output( "done.\n" ); + if ( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_OLD ) { + # Get "active" text records from the revisions table + $cur = []; + $this->output( 'Searching for active text records in revisions table...' ); + $res = $dbw->select( 'revision', 'rev_text_id', [], __METHOD__, [ 'DISTINCT' ] ); + foreach ( $res as $row ) { + $cur[] = $row->rev_text_id; + } + $this->output( "done.\n" ); - # Get "active" text records from the archive table - $this->output( 'Searching for active text records in archive table...' ); - $res = $dbw->select( 'archive', 'ar_text_id', [], __METHOD__, [ 'DISTINCT' ] ); - foreach ( $res as $row ) { - # old pre-MW 1.5 records can have null ar_text_id's. - if ( $row->ar_text_id !== null ) { - $cur[] = $row->ar_text_id; + # Get "active" text records from the archive table + $this->output( 'Searching for active text records in archive table...' ); + $res = $dbw->select( 'archive', 'ar_text_id', [], __METHOD__, [ 'DISTINCT' ] ); + foreach ( $res as $row ) { + # old pre-MW 1.5 records can have null ar_text_id's. + if ( $row->ar_text_id !== null ) { + $cur[] = $row->ar_text_id; + } + } + $this->output( "done.\n" ); + } else { + # Get "active" text records via the content table + $cur = []; + $this->output( 'Searching for active text records via contents table...' ); + $res = $dbw->select( 'content', 'content_address', [], __METHOD__, [ 'DISTINCT' ] ); + $blobStore = MediaWikiServices::getInstance()->getBlobStore(); + foreach ( $res as $row ) { + $textId = $blobStore->getTextIdFromAddress( $row->content_address ); + if ( $textId ) { + $cur[] = $textId; + } } + $this->output( "done.\n" ); } $this->output( "done.\n" ); diff --git a/maintenance/populateContentTables.php b/maintenance/populateContentTables.php index 644ff87ee8..a264545e7f 100644 --- a/maintenance/populateContentTables.php +++ b/maintenance/populateContentTables.php @@ -188,6 +188,11 @@ class PopulateContentTables extends Maintenance { $startOption = 'start-archive'; } + if ( !$this->dbw->fieldExists( $table, $fields['text_id'], __METHOD__ ) ) { + $this->writeln( "No need to populate, $table.{$fields['text_id']} field does not exist" ); + return; + } + $minmax = $this->dbw->selectRow( $table, [ 'min' => "MIN( $idField )", 'max' => "MAX( $idField )" ], diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php index 900a52a570..2e4cc88058 100644 --- a/maintenance/rebuildtextindex.php +++ b/maintenance/rebuildtextindex.php @@ -93,7 +93,7 @@ class RebuildTextIndex extends Maintenance { $this->output( "Rebuilding index fields for {$count} pages...\n" ); $n = 0; - $revQuery = Revision::getQueryInfo( [ 'page', 'text' ] ); + $revQuery = Revision::getQueryInfo( [ 'page' ] ); while ( $n < $count ) { if ( $n ) { @@ -104,7 +104,7 @@ class RebuildTextIndex extends Maintenance { $res = $this->db->select( $revQuery['tables'], $revQuery['fields'], - [ "page_id BETWEEN $n AND $end", 'page_latest = rev_id', 'rev_text_id = old_id' ], + [ "page_id BETWEEN $n AND $end", 'page_latest = rev_id' ], __METHOD__, [], $revQuery['joins'] diff --git a/tests/phpunit/includes/ActorMigrationTest.php b/tests/phpunit/includes/ActorMigrationTest.php index 15c70bce11..1f2b13cfa8 100644 --- a/tests/phpunit/includes/ActorMigrationTest.php +++ b/tests/phpunit/includes/ActorMigrationTest.php @@ -593,7 +593,6 @@ class ActorMigrationTest extends MediaWikiLangTestCase { ] ], 'revision' => [ 'revision', 'rev_user', 'rev_id', [ 'rev_page' => 42, - 'rev_text_id' => 42, 'rev_len' => 0, 'rev_timestamp' => $db->timestamp(), ] ], @@ -679,7 +678,6 @@ class ActorMigrationTest extends MediaWikiLangTestCase { $m->getInsertValuesWithTempTable( $this->db, 'rev_user', $userIdentity ); $extraFields = [ 'rev_page' => 42, - 'rev_text_id' => 42, 'rev_len' => 0, 'rev_timestamp' => $this->db->timestamp(), ] + $cFields; -- 2.20.1