mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-23 15:36:52 +00:00
Force the use of the category index when paging by category
The EXPLAIN in P70205#281191 shows the PRIMARY index being used, resulting in a long scan in newer categories where all the linter_id are higher. Bug: T200517 Change-Id: I373692942121ff555565c9c2c310087cd097ef21
This commit is contained in:
parent
4029d93e77
commit
be1f60b6ea
|
@ -51,11 +51,14 @@ class ApiQueryLintErrors extends ApiQueryBase {
|
|||
$this->requireMaxOneParameter( $params, 'pageid', 'title' );
|
||||
$this->requireMaxOneParameter( $params, 'namespace', 'title' );
|
||||
|
||||
$useIndex = true;
|
||||
$categories = $params['categories'];
|
||||
if ( !$categories ) {
|
||||
$categories = $this->categoryManager->getVisibleCategories();
|
||||
}
|
||||
|
||||
if ( count( $categories ) > 1 ) {
|
||||
$useIndex = false;
|
||||
}
|
||||
$this->addTables( 'linter' );
|
||||
$this->addWhereFld( 'linter_cat', array_values( $this->categoryManager->getCategoryIds(
|
||||
$categories
|
||||
|
@ -67,14 +70,17 @@ class ApiQueryLintErrors extends ApiQueryBase {
|
|||
if ( $params['pageid'] !== null ) {
|
||||
// This can be an array or a single pageid
|
||||
$this->addWhereFld( 'linter_page', $params['pageid'] );
|
||||
$useIndex = false;
|
||||
}
|
||||
if ( $params['namespace'] !== null ) {
|
||||
$this->addWhereFld( 'page_namespace', $params['namespace'] );
|
||||
$useIndex = false;
|
||||
}
|
||||
if ( $params['title'] !== null ) {
|
||||
$title = $this->getTitleFromTitleOrPageId( [ 'title' => $params['title'] ] );
|
||||
$this->addWhereFld( 'page_namespace', $title->getNamespace() );
|
||||
$this->addWhereFld( 'page_title', $title->getDBkey() );
|
||||
$useIndex = false;
|
||||
}
|
||||
$this->addTables( 'page' );
|
||||
$this->addJoinConds( [ 'page' => [ 'INNER JOIN', 'page_id=linter_page' ] ] );
|
||||
|
@ -83,6 +89,10 @@ class ApiQueryLintErrors extends ApiQueryBase {
|
|||
'linter_start', 'linter_end',
|
||||
'page_namespace', 'page_title',
|
||||
] );
|
||||
if ( $useIndex ) {
|
||||
// T200517#10236299: Force the use of the category index
|
||||
$this->addOption( 'USE INDEX', [ 'linter' => 'linter_cat_page_position' ] );
|
||||
}
|
||||
// Be explicit about ORDER BY
|
||||
$this->addOption( 'ORDER BY', 'linter_id' );
|
||||
// Add +1 to limit to know if there's another row for continuation
|
||||
|
|
|
@ -116,6 +116,8 @@ class LintErrorsPager extends TablePager {
|
|||
] )
|
||||
->where( [ 'linter_cat' => $this->categoryId ] );
|
||||
|
||||
$useIndex = false;
|
||||
|
||||
if ( $this->title !== '' ) {
|
||||
$namespaces = $this->namespaces ?: [ NS_MAIN ];
|
||||
// Specify page_namespace so that the index can be used (T360865)
|
||||
|
@ -134,15 +136,24 @@ class LintErrorsPager extends TablePager {
|
|||
}
|
||||
} elseif ( $this->namespaces ) {
|
||||
$queryBuilder->where( [ 'linter_namespace' => $this->namespaces ] );
|
||||
} else {
|
||||
$useIndex = true;
|
||||
}
|
||||
|
||||
if ( $this->throughTemplate !== 'all' ) {
|
||||
$useIndex = false;
|
||||
$op = ( $this->throughTemplate === 'with' ) ? '!=' : '=';
|
||||
$queryBuilder->where( $this->mDb->expr( 'linter_template', $op, '' ) );
|
||||
}
|
||||
if ( $this->tag !== 'all' && ( new HtmlTags( $this ) )->checkAllowedHTMLTags( $this->tag ) ) {
|
||||
$useIndex = false;
|
||||
$queryBuilder->where( [ 'linter_tag' => $this->tag ] );
|
||||
}
|
||||
|
||||
if ( $useIndex ) {
|
||||
// T200517#10236299: Force the use of the category index
|
||||
$queryBuilder->option( 'USE INDEX', [ 'linter' => 'linter_cat_page_position' ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue