Use expression builder instead of raw sql

Change-Id: I0cb5fa07d63bc93089a4956097eee7a41dbc99e7
This commit is contained in:
Umherirrender 2024-07-21 22:59:23 +02:00
parent a0b8933a41
commit 2a932e598c
5 changed files with 10 additions and 11 deletions

View file

@ -7,7 +7,7 @@
"descriptionmsg": "discussiontools-desc",
"manifest_version": 2,
"requires": {
"MediaWiki": ">= 1.42.0",
"MediaWiki": ">= 1.43.0",
"extensions": {
"VisualEditor": "*",
"Linter": "*"

View file

@ -87,6 +87,7 @@ class ThreadItemStore {
return [];
}
$dbr = $this->dbProvider->getReplicaDatabase();
$queryBuilder = $this->getIdsNamesBuilder()
->caller( __METHOD__ )
->where( [
@ -94,7 +95,7 @@ class ThreadItemStore {
// Disallow querying for headings of sections that contain no comments.
// They all share the same name, so this would return a huge useless list on most wikis.
// (But we still store them, as we might need this data elsewhere.)
"it_itemname != 'h-'",
$dbr->expr( 'it_itemname', '!=', 'h-' ),
] );
if ( $limit !== null ) {
@ -141,10 +142,11 @@ class ThreadItemStore {
// It might scan a bunch of rows...
// ->limit( 1 );
$dbr = $this->dbProvider->getReplicaDatabase();
$queryBuilder
->where( [
'it_itemname IN (' . $itemNameQueryBuilder->getSQL() . ')',
"it_itemname != 'h-'",
$dbr->expr( 'it_itemname', '!=', 'h-' ),
] );
if ( $limit !== null ) {

View file

@ -264,7 +264,7 @@ class TopicSubscriptionsPager extends TablePager {
],
'conds' => [
'sub_user' => $this->getUser()->getId(),
'sub_state != ' . SubscriptionStore::STATE_UNSUBSCRIBED,
$this->getDatabase()->expr( 'sub_state', '!=', SubscriptionStore::STATE_UNSUBSCRIBED ),
],
];
}

View file

@ -4,7 +4,6 @@ namespace MediaWiki\Extension\DiscussionTools\Maintenance;
use LoggedUpdateMaintenance;
use Wikimedia\Rdbms\DBQueryError;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\IExpression;
use Wikimedia\Rdbms\LikeValue;
@ -54,19 +53,17 @@ class FixTrailingWhitespaceIds extends LoggedUpdateMaintenance {
->from( 'discussiontools_item_ids' )
->field( 'itid_itemid' )
->where(
$dbw->makeList( [
$dbw->orExpr( [
$dbw->expr( 'itid_itemid', IExpression::LIKE, $like1 ),
$dbw->expr( 'itid_itemid', IExpression::LIKE, $like2 ),
$dbw->expr( 'itid_itemid', IExpression::LIKE, $like3 ),
], IDatabase::LIST_OR )
] )
)
->caller( __METHOD__ )
->limit( $this->getBatchSize() );
if ( $skippedIds ) {
$itemIdQueryBuilder->where(
'itid_itemid NOT IN (' . $dbw->makeList( $skippedIds ) . ')'
);
$itemIdQueryBuilder->where( $dbw->expr( 'itid_itemid', '!=', $skippedIds ) );
}
$itemIds = $itemIdQueryBuilder->fetchFieldValues();

View file

@ -45,7 +45,7 @@ class NewTopicOptOutActiveUsers extends Maintenance {
'qcc_namespace' => NS_USER,
] )
->join( 'user', null, 'qcc_title=user_name' )
->where( [ 'user_editcount >= 100' ] )
->where( $this->dbw->expr( 'user_editcount', '>=', 100 ) )
->fields( [ 'user_id', 'user_name' ] )
->fetchResultSet();