Remove linter namespace field dual mode config and code

* Manual tests completed and query code reviewed

Bug: T331883
Change-Id: Ie1628799bb40ad74a24ab57a27a4176c2364fb82
This commit is contained in:
sbailey 2024-06-03 12:22:07 -07:00
parent 4364a1f13f
commit 72653441b2
5 changed files with 39 additions and 58 deletions

View file

@ -240,12 +240,6 @@
"LinterStatsdSampleFactor": {
"value": false
},
"LinterWriteNamespaceColumnStage": {
"value": false
},
"LinterUseNamespaceColumnStage": {
"value": false
},
"LinterWriteTagAndTemplateColumnsStage": {
"value": false
},

View file

@ -34,7 +34,6 @@ use Wikimedia\Rdbms\SelectQueryBuilder;
*/
class Database {
public const CONSTRUCTOR_OPTIONS = [
'LinterWriteNamespaceColumnStage',
'LinterWriteTagAndTemplateColumnsStage',
];
@ -176,24 +175,10 @@ class Database {
'linter_cat' => $this->categoryManager->getCategoryId( $error->category, $error->catId ),
'linter_params' => FormatJson::encode( $error->params, false, FormatJson::ALL_OK ),
'linter_start' => $error->location[ 0 ],
'linter_end' => $error->location[ 1 ]
'linter_end' => $error->location[ 1 ],
'linter_namespace' => $namespaceId
];
// To enable 756101
//
// During the addition of this column to the table, the initial value
// of null allows the migrate stage code to determine the needs to fill
// in the field for that record, as the record was created prior to the
// write stage code being active and filling it in during record
// creation. Once the migrate code runs once no nulls should exist in
// this field for any record, and if the migrate code times out during
// execution, can be restarted and continue without duplicating work.
// The final code that enables the use of this field during records
// search will depend on this fields index being valid for all records.
if ( $this->options->get( 'LinterWriteNamespaceColumnStage' ) ) {
$result[ 'linter_namespace' ] = $namespaceId;
}
// To enable 720130
if ( $this->options->get( 'LinterWriteTagAndTemplateColumnsStage' ) ) {
$templateInfo = $error->templateInfo ?? '';
@ -402,19 +387,11 @@ class Database {
* @param int $pageBatchSize
* @param int $linterBatchSize
* @param int $sleep
* @param bool $bypassConfig
* @return int number of pages updated, each with one or more linter records
*/
public function migrateNamespace(
int $pageBatchSize, int $linterBatchSize, int $sleep,
bool $bypassConfig = false
int $pageBatchSize, int $linterBatchSize, int $sleep
): int {
// code used by phpunit test, bypassed when run as a maintenance script
if ( !$bypassConfig ) {
if ( !$this->options->get( 'LinterWriteNamespaceColumnStage' ) ) {
return 0;
}
}
if ( gettype( $sleep ) !== 'integer' || $sleep < 0 ) {
$sleep = 0;
}

View file

@ -119,12 +119,10 @@ class LintErrorsPager extends TablePager {
if ( $this->title !== '' ) {
$namespaces = $this->namespaces ?: [ NS_MAIN ];
// Specify page_namespace so that the index can be used (T360865)
$queryBuilder->where( [ 'page_namespace' => $namespaces ] );
if ( $mainConfig->get( 'LinterUseNamespaceColumnStage' ) ) {
// Also put a condition on linter_namespace, in case the DB
// decides to put the linter table first
$queryBuilder->where( [ 'linter_namespace' => $namespaces ] );
}
// Also put a condition on linter_namespace, in case the DB
// decides to put the linter table first
$queryBuilder->where( [ 'page_namespace' => $namespaces, 'linter_namespace' => $namespaces ] );
if ( $this->exactMatch ) {
$queryBuilder->where( [
'page_title' => $this->title
@ -135,9 +133,7 @@ class LintErrorsPager extends TablePager {
) );
}
} elseif ( $this->namespaces ) {
$namespaceCol = $mainConfig->get( 'LinterUseNamespaceColumnStage' )
? "linter_namespace" : "page_namespace";
$queryBuilder->where( [ $namespaceCol => $this->namespaces ] );
$queryBuilder->where( [ 'linter_namespace' => $this->namespaces ] );
}
if ( $mainConfig->get( 'LinterUserInterfaceTagAndTemplateStage' ) ) {

View file

@ -3,9 +3,9 @@
/**
* Maintenance script that migrates the page table page_namespace field values
* to the linter table linter_namespace field to improve linter search performance.
* note: This should be run once the namespace write functionality in linter
* recordLintJob has been enabled by setting LinterWriteNamespaceColumnStage true.
* note: This code is based on migrateRevisionActorTemp.php and migrateLinksTable.php
* Note: The schema migration "patch-linter-add-namespace.json" is expected to have been done.
* The extension now populates this new field by default. This script will migrate any data
* in existing records to this new field.
*/
$IP = getenv( 'MW_INSTALL_PATH' );
@ -40,11 +40,6 @@ class MigrateNamespace extends LoggedUpdateMaintenance {
*/
protected function doDBUpdates() {
$config = $this->getConfig();
$enableMigrateNamespaceStage = $config->get( 'LinterWriteNamespaceColumnStage' );
if ( !$enableMigrateNamespaceStage ) {
$this->output( "LinterWriteNamespaceColumnStage config value is false, code is disabled, exiting\n" );
return false;
}
$this->output( "Running linter migrate namespace function, this may take a while\n" );
@ -60,7 +55,7 @@ class MigrateNamespace extends LoggedUpdateMaintenance {
$this->output( "Migrating the page table page_namespace field to the linter table...\n" );
$database = $this->getServiceContainer()->get( 'Linter.Database' );
$updated = $database->migrateNamespace( $batchSize, $batchSize, $sleep, false );
$updated = $database->migrateNamespace( $batchSize, $batchSize, $sleep );
$this->output( "Completed migration of page_namespace data to the linter table, $updated rows updated.\n" );

View file

@ -26,6 +26,7 @@ use MediaWiki\Page\PageReference;
use MediaWiki\Title\Title;
use MediaWikiIntegrationTestCase;
use Wikimedia\Rdbms\SelectQueryBuilder;
use Wikimedia\Rdbms\UpdateQueryBuilder;
/**
* @group Database
@ -111,6 +112,21 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
return $queryLinterPageNamespace->fetchField();
}
/**
* Set just the linter_namespace field value from the linter table for a page
*
* @param int $pageId
*/
private function setNamespaceForPageToNull( int $pageId ) {
$queryLinterPageNamespace = new UpdateQueryBuilder( $this->db );
$queryLinterPageNamespace
->update( 'linter' )
->set( [ 'linter_namespace' => null ] )
->where( [ 'linter_page' => $pageId ] )
->caller( __METHOD__ )
->execute();
}
public function testRun() {
$error = [
'type' => 'fostered',
@ -227,17 +243,20 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
/**
* @param array $namespaceIds
* @param array $writeEnables
* @param array $setToID
* @return array
*/
private function createPagesWithNamespace( array $namespaceIds, array $writeEnables ): array {
private function createPagesWithNamespace( array $namespaceIds, array $setToID ): array {
$titleAndPages = [];
foreach ( $namespaceIds as $index => $namespaceId ) {
// enable/disable writing the namespace field in the linter table during page creation
$this->overrideConfigValue( 'LinterWriteNamespaceColumnStage', $writeEnables[ $index ] );
$titleAndPages[] = $this->createTitleAndPageAndRunJob(
$titleAndPage = $this->createTitleAndPageAndRunJob(
'TestPageNamespace' . $index,
intval( $namespaceId ) );
$titleAndPages[] = $titleAndPage;
// To test the migration code, set some namespaces to null to simulate having a mix of valid and null values
if ( !$setToID[ $index ] ) {
$this->setNamespaceForPageToNull( $titleAndPage['pageID'] );
}
}
return $titleAndPages;
}
@ -259,9 +278,9 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
public function testMigrateNamespace() {
// Create groups of records that do not need migrating to ensure batching works properly
$namespaceIds = [ '0', '1', '2', '3', '4', '5', '4', '3', '2', '1', '0', '1', '2' ];
$writeEnables = [ false, true, true, true, false, false, true, true, false, false, false, true, false ];
$setToID = [ false, true, true, true, false, false, true, true, false, false, false, true, false ];
$titleAndPages = $this->createPagesWithNamespace( $namespaceIds, $writeEnables );
$titleAndPages = $this->createPagesWithNamespace( $namespaceIds, $setToID );
// Verify the create page function did not populate the linter_namespace field for TestPageNamespace0
$pageId = $titleAndPages[ 0 ][ 'pageID' ];
@ -270,7 +289,7 @@ class RecordLintJobTest extends MediaWikiIntegrationTestCase {
// migrate unpopulated namespace_id(s) from the page table to linter table
$database = $this->getDatabase();
$database->migrateNamespace( 2, 3, 0, true );
$database->migrateNamespace( 2, 3, 0 );
// Verify all linter records now have proper namespace IDs in the linter_namespace field
$this->checkPagesNamespace( $titleAndPages, $namespaceIds );