mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-23 23:44:17 +00:00
Merge "Force the use of the category index when paging by category"
This commit is contained in:
commit
f3e9a38c96
|
@ -51,11 +51,14 @@ class ApiQueryLintErrors extends ApiQueryBase {
|
||||||
$this->requireMaxOneParameter( $params, 'pageid', 'title' );
|
$this->requireMaxOneParameter( $params, 'pageid', 'title' );
|
||||||
$this->requireMaxOneParameter( $params, 'namespace', 'title' );
|
$this->requireMaxOneParameter( $params, 'namespace', 'title' );
|
||||||
|
|
||||||
|
$useIndex = true;
|
||||||
$categories = $params['categories'];
|
$categories = $params['categories'];
|
||||||
if ( !$categories ) {
|
if ( !$categories ) {
|
||||||
$categories = $this->categoryManager->getVisibleCategories();
|
$categories = $this->categoryManager->getVisibleCategories();
|
||||||
}
|
}
|
||||||
|
if ( count( $categories ) > 1 ) {
|
||||||
|
$useIndex = false;
|
||||||
|
}
|
||||||
$this->addTables( 'linter' );
|
$this->addTables( 'linter' );
|
||||||
$this->addWhereFld( 'linter_cat', array_values( $this->categoryManager->getCategoryIds(
|
$this->addWhereFld( 'linter_cat', array_values( $this->categoryManager->getCategoryIds(
|
||||||
$categories
|
$categories
|
||||||
|
@ -67,14 +70,17 @@ class ApiQueryLintErrors extends ApiQueryBase {
|
||||||
if ( $params['pageid'] !== null ) {
|
if ( $params['pageid'] !== null ) {
|
||||||
// This can be an array or a single pageid
|
// This can be an array or a single pageid
|
||||||
$this->addWhereFld( 'linter_page', $params['pageid'] );
|
$this->addWhereFld( 'linter_page', $params['pageid'] );
|
||||||
|
$useIndex = false;
|
||||||
}
|
}
|
||||||
if ( $params['namespace'] !== null ) {
|
if ( $params['namespace'] !== null ) {
|
||||||
$this->addWhereFld( 'page_namespace', $params['namespace'] );
|
$this->addWhereFld( 'page_namespace', $params['namespace'] );
|
||||||
|
$useIndex = false;
|
||||||
}
|
}
|
||||||
if ( $params['title'] !== null ) {
|
if ( $params['title'] !== null ) {
|
||||||
$title = $this->getTitleFromTitleOrPageId( [ 'title' => $params['title'] ] );
|
$title = $this->getTitleFromTitleOrPageId( [ 'title' => $params['title'] ] );
|
||||||
$this->addWhereFld( 'page_namespace', $title->getNamespace() );
|
$this->addWhereFld( 'page_namespace', $title->getNamespace() );
|
||||||
$this->addWhereFld( 'page_title', $title->getDBkey() );
|
$this->addWhereFld( 'page_title', $title->getDBkey() );
|
||||||
|
$useIndex = false;
|
||||||
}
|
}
|
||||||
$this->addTables( 'page' );
|
$this->addTables( 'page' );
|
||||||
$this->addJoinConds( [ 'page' => [ 'INNER JOIN', 'page_id=linter_page' ] ] );
|
$this->addJoinConds( [ 'page' => [ 'INNER JOIN', 'page_id=linter_page' ] ] );
|
||||||
|
@ -83,6 +89,10 @@ class ApiQueryLintErrors extends ApiQueryBase {
|
||||||
'linter_start', 'linter_end',
|
'linter_start', 'linter_end',
|
||||||
'page_namespace', 'page_title',
|
'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
|
// Be explicit about ORDER BY
|
||||||
$this->addOption( 'ORDER BY', 'linter_id' );
|
$this->addOption( 'ORDER BY', 'linter_id' );
|
||||||
// Add +1 to limit to know if there's another row for continuation
|
// 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 ] );
|
->where( [ 'linter_cat' => $this->categoryId ] );
|
||||||
|
|
||||||
|
$useIndex = false;
|
||||||
|
|
||||||
if ( $this->title !== '' ) {
|
if ( $this->title !== '' ) {
|
||||||
$namespaces = $this->namespaces ?: [ NS_MAIN ];
|
$namespaces = $this->namespaces ?: [ NS_MAIN ];
|
||||||
// Specify page_namespace so that the index can be used (T360865)
|
// Specify page_namespace so that the index can be used (T360865)
|
||||||
|
@ -134,15 +136,24 @@ class LintErrorsPager extends TablePager {
|
||||||
}
|
}
|
||||||
} elseif ( $this->namespaces ) {
|
} elseif ( $this->namespaces ) {
|
||||||
$queryBuilder->where( [ 'linter_namespace' => $this->namespaces ] );
|
$queryBuilder->where( [ 'linter_namespace' => $this->namespaces ] );
|
||||||
|
} else {
|
||||||
|
$useIndex = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->throughTemplate !== 'all' ) {
|
if ( $this->throughTemplate !== 'all' ) {
|
||||||
|
$useIndex = false;
|
||||||
$op = ( $this->throughTemplate === 'with' ) ? '!=' : '=';
|
$op = ( $this->throughTemplate === 'with' ) ? '!=' : '=';
|
||||||
$queryBuilder->where( $this->mDb->expr( 'linter_template', $op, '' ) );
|
$queryBuilder->where( $this->mDb->expr( 'linter_template', $op, '' ) );
|
||||||
}
|
}
|
||||||
if ( $this->tag !== 'all' && ( new HtmlTags( $this ) )->checkAllowedHTMLTags( $this->tag ) ) {
|
if ( $this->tag !== 'all' && ( new HtmlTags( $this ) )->checkAllowedHTMLTags( $this->tag ) ) {
|
||||||
|
$useIndex = false;
|
||||||
$queryBuilder->where( [ 'linter_tag' => $this->tag ] );
|
$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