Remove many references to db fields being retired as part of MCR Schema Migration
authorBill Pirkle <bpirkle@wikimedia.org>
Fri, 15 Mar 2019 15:59:41 +0000 (10:59 -0500)
committerBill Pirkle <bpirkle@wikimedia.org>
Tue, 19 Mar 2019 15:50:54 +0000 (10:50 -0500)
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
includes/cache/MessageCache.php
maintenance/Maintenance.php
maintenance/populateContentTables.php
maintenance/rebuildtextindex.php
tests/phpunit/includes/ActorMigrationTest.php

index 7e548ab..5b178b7 100644 (file)
@@ -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;
index b669fcd..e78dfa1 100644 (file)
@@ -48,7 +48,7 @@ class MessageCache {
        /**
         * Process cache of loaded messages that are defined in MediaWiki namespace
         *
-        * @var MapCacheLRU Map of (language code => key => " <MESSAGE>" or "!TOO BIG")
+        * @var MapCacheLRU Map of (language code => key => " <MESSAGE>" 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
index b638b42..ad748f3 100644 (file)
@@ -1281,27 +1281,45 @@ abstract class Maintenance {
         * @author Rob Church <robchur@gmail.com>
         */
        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" );
 
index 644ff87..a264545 100644 (file)
@@ -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 )" ],
index 900a52a..2e4cc88 100644 (file)
@@ -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']
index 15c70bc..1f2b13c 100644 (file)
@@ -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;