Avoid small code duplication in BacklinkCache
Reuse $fromField to build the _from field name Also build it only when needed and do not hard code AS, let it add by the abstract database layer Change-Id: I2c3a2a863b963fb7f24c02e1ce44a56fccea95e5
This commit is contained in:
parent
7a36d66d75
commit
8660ca657d
1 changed files with 2 additions and 3 deletions
5
includes/cache/BacklinkCache.php
vendored
5
includes/cache/BacklinkCache.php
vendored
|
|
@ -182,8 +182,6 @@ class BacklinkCache {
|
|||
* @return IResultWrapper
|
||||
*/
|
||||
protected function queryLinks( $table, $startId, $endId, $max, $select = 'all' ) {
|
||||
$fromField = $this->getPrefix( $table ) . '_from';
|
||||
|
||||
if ( !$startId && !$endId && is_infinite( $max )
|
||||
&& isset( $this->fullResultCache[$table] )
|
||||
) {
|
||||
|
|
@ -191,6 +189,7 @@ class BacklinkCache {
|
|||
$res = $this->fullResultCache[$table];
|
||||
} else {
|
||||
wfDebug( __METHOD__ . ": got results from DB\n" );
|
||||
$fromField = $this->getPrefix( $table ) . '_from';
|
||||
$conds = $this->getConditions( $table );
|
||||
// Use the from field in the condition rather than the joined page_id,
|
||||
// because databases are stupid and don't necessarily propagate indexes.
|
||||
|
|
@ -209,7 +208,7 @@ class BacklinkCache {
|
|||
// Just select from the backlink table and ignore the page JOIN
|
||||
$res = $this->getDB()->select(
|
||||
$table,
|
||||
[ $this->getPrefix( $table ) . '_from AS page_id' ],
|
||||
[ 'page_id' => $fromField ],
|
||||
array_filter( $conds, function ( $clause ) { // kind of janky
|
||||
return !preg_match( '/(\b|=)page_id(\b|=)/', $clause );
|
||||
} ),
|
||||
|
|
|
|||
Loading…
Reference in a new issue