diff --git a/includes/PageImages.php b/includes/PageImages.php index e70b9f0..a0c56b7 100644 --- a/includes/PageImages.php +++ b/includes/PageImages.php @@ -189,15 +189,16 @@ class PageImages implements } $dbr = $this->dbProvider->getReplicaDatabase(); - $fileName = $dbr->selectField( 'page_props', - 'pp_value', - [ + $fileName = $dbr->newSelectQueryBuilder() + ->select( 'pp_value' ) + ->from( 'page_props' ) + ->where( [ 'pp_page' => $pageId, 'pp_propname' => [ self::PROP_NAME, self::PROP_NAME_FREE ] - ], - __METHOD__, - [ 'ORDER BY' => 'pp_propname' ] - ); + ] ) + ->orderBy( 'pp_propname' ) + ->caller( __METHOD__ ) + ->fetchField(); if ( !$fileName ) { // Return not found without caching. return false; diff --git a/maintenance/initImageData.php b/maintenance/initImageData.php index 3322418..84d0ebb 100644 --- a/maintenance/initImageData.php +++ b/maintenance/initImageData.php @@ -45,41 +45,40 @@ class InitImageData extends Maintenance { } 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() ->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' ) ) { $ns = explode( ',', $this->getOption( 'namespaces' ) ); - $conds['page_namespace'] = $ns; + $queryBuilder->andWhere( [ 'page_namespace' => $ns ] ); } else { - $conds['page_namespace'] = $this->getServiceContainer()->getMainConfig()->get( 'PageImagesNamespaces' ); + $queryBuilder->andWhere( [ + 'page_namespace' => $this->getServiceContainer()->getMainConfig()->get( 'PageImagesNamespaces' ) + ] ); } if ( $this->hasOption( 'earlier-than' ) ) { - $conds[] = 'page_touched < ' - . $dbr->addQuotes( $dbr->timestamp( $this->getOption( 'earlier-than' ) ) ); + $queryBuilder->andWhere( + $dbr->expr( 'page_touched', '<', $dbr->timestamp( $this->getOption( 'earlier-than' ) ) ) + ); } if ( $this->hasOption( 'later-than' ) ) { - $conds[] = 'page_touched > ' - . $dbr->addQuotes( $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; + $queryBuilder->andWhere( + $dbr->expr( 'page_touched', '>', $dbr->timestamp( $this->getOption( 'later-than' ) ) ) + ); } + $pageIds = $queryBuilder->fetchFieldValues(); $job = new InitImageDataJob( Title::newMainPage(), [ 'page_ids' => $pageIds ], @@ -93,7 +92,7 @@ class InitImageData extends Maintenance { } $lastId = end( $pageIds ); $this->output( "$lastId\n" ); - } while ( $res->numRows() ); + } while ( $pageIds ); $this->output( "done\n" ); }