mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-11-27 17:50:53 +00:00
Migrate to IReadableDatabase::newSelectQueryBuilder
Also use expression builder to avoid raw sql Bug: T312501 Bug: T350988 Change-Id: I0ea6aa6edcd68cba067260dad560b87283cca020
This commit is contained in:
parent
dd36c6e13e
commit
d0c0dc9caf
|
@ -189,15 +189,16 @@ class PageImages implements
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbr = $this->dbProvider->getReplicaDatabase();
|
$dbr = $this->dbProvider->getReplicaDatabase();
|
||||||
$fileName = $dbr->selectField( 'page_props',
|
$fileName = $dbr->newSelectQueryBuilder()
|
||||||
'pp_value',
|
->select( 'pp_value' )
|
||||||
[
|
->from( 'page_props' )
|
||||||
|
->where( [
|
||||||
'pp_page' => $pageId,
|
'pp_page' => $pageId,
|
||||||
'pp_propname' => [ self::PROP_NAME, self::PROP_NAME_FREE ]
|
'pp_propname' => [ self::PROP_NAME, self::PROP_NAME_FREE ]
|
||||||
],
|
] )
|
||||||
__METHOD__,
|
->orderBy( 'pp_propname' )
|
||||||
[ 'ORDER BY' => 'pp_propname' ]
|
->caller( __METHOD__ )
|
||||||
);
|
->fetchField();
|
||||||
if ( !$fileName ) {
|
if ( !$fileName ) {
|
||||||
// Return not found without caching.
|
// Return not found without caching.
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -45,41 +45,40 @@ class InitImageData extends Maintenance {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$tables = [ 'page', 'imagelinks' ];
|
|
||||||
$conds = [
|
|
||||||
'page_id > ' . (int)$lastId,
|
|
||||||
'il_from IS NOT NULL',
|
|
||||||
'page_is_redirect' => 0,
|
|
||||||
];
|
|
||||||
$fields = [ 'page_id' ];
|
|
||||||
$joinConds = [ 'imagelinks' => [
|
|
||||||
'LEFT JOIN', 'page_id = il_from',
|
|
||||||
] ];
|
|
||||||
|
|
||||||
$dbr = $this->getServiceContainer()->getDBLoadBalancerFactory()
|
$dbr = $this->getServiceContainer()->getDBLoadBalancerFactory()
|
||||||
->getReplicaDatabase();
|
->getReplicaDatabase();
|
||||||
|
$queryBuilder = $dbr->newSelectQueryBuilder()
|
||||||
|
->select( 'page_id' )
|
||||||
|
->from( 'page' )
|
||||||
|
->leftJoin( 'imagelinks', null, 'page_id = il_from' )
|
||||||
|
->where( [
|
||||||
|
$dbr->expr( 'page_id', '>', (int)$lastId ),
|
||||||
|
$dbr->expr( 'il_from', '!=', null ),
|
||||||
|
'page_is_redirect' => 0,
|
||||||
|
] )
|
||||||
|
->orderBy( 'page_id' )
|
||||||
|
->groupBy( 'page_id' )
|
||||||
|
->limit( $this->mBatchSize )
|
||||||
|
->caller( __METHOD__ );
|
||||||
if ( $this->hasOption( 'namespaces' ) ) {
|
if ( $this->hasOption( 'namespaces' ) ) {
|
||||||
$ns = explode( ',', $this->getOption( 'namespaces' ) );
|
$ns = explode( ',', $this->getOption( 'namespaces' ) );
|
||||||
$conds['page_namespace'] = $ns;
|
$queryBuilder->andWhere( [ 'page_namespace' => $ns ] );
|
||||||
} else {
|
} else {
|
||||||
$conds['page_namespace'] = $this->getServiceContainer()->getMainConfig()->get( 'PageImagesNamespaces' );
|
$queryBuilder->andWhere( [
|
||||||
|
'page_namespace' => $this->getServiceContainer()->getMainConfig()->get( 'PageImagesNamespaces' )
|
||||||
|
] );
|
||||||
}
|
}
|
||||||
if ( $this->hasOption( 'earlier-than' ) ) {
|
if ( $this->hasOption( 'earlier-than' ) ) {
|
||||||
$conds[] = 'page_touched < '
|
$queryBuilder->andWhere(
|
||||||
. $dbr->addQuotes( $dbr->timestamp( $this->getOption( 'earlier-than' ) ) );
|
$dbr->expr( 'page_touched', '<', $dbr->timestamp( $this->getOption( 'earlier-than' ) ) )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if ( $this->hasOption( 'later-than' ) ) {
|
if ( $this->hasOption( 'later-than' ) ) {
|
||||||
$conds[] = 'page_touched > '
|
$queryBuilder->andWhere(
|
||||||
. $dbr->addQuotes( $dbr->timestamp( $this->getOption( 'later-than' ) ) );
|
$dbr->expr( 'page_touched', '>', $dbr->timestamp( $this->getOption( 'later-than' ) ) )
|
||||||
}
|
);
|
||||||
$res = $dbr->select( $tables, $fields, $conds, __METHOD__,
|
|
||||||
[ 'LIMIT' => $this->mBatchSize, 'ORDER_BY' => 'page_id', 'GROUP BY' => 'page_id' ],
|
|
||||||
$joinConds
|
|
||||||
);
|
|
||||||
$pageIds = [];
|
|
||||||
foreach ( $res as $row ) {
|
|
||||||
$pageIds[] = $row->page_id;
|
|
||||||
}
|
}
|
||||||
|
$pageIds = $queryBuilder->fetchFieldValues();
|
||||||
$job = new InitImageDataJob(
|
$job = new InitImageDataJob(
|
||||||
Title::newMainPage(),
|
Title::newMainPage(),
|
||||||
[ 'page_ids' => $pageIds ],
|
[ 'page_ids' => $pageIds ],
|
||||||
|
@ -93,7 +92,7 @@ class InitImageData extends Maintenance {
|
||||||
}
|
}
|
||||||
$lastId = end( $pageIds );
|
$lastId = end( $pageIds );
|
||||||
$this->output( "$lastId\n" );
|
$this->output( "$lastId\n" );
|
||||||
} while ( $res->numRows() );
|
} while ( $pageIds );
|
||||||
$this->output( "done\n" );
|
$this->output( "done\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue