From 8660ca657d714f2db02cc622654736d380e7adf8 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Thu, 7 May 2020 22:17:02 +0200 Subject: [PATCH] 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 --- includes/cache/BacklinkCache.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/cache/BacklinkCache.php b/includes/cache/BacklinkCache.php index c6ea7bf5a66..81108532c64 100644 --- a/includes/cache/BacklinkCache.php +++ b/includes/cache/BacklinkCache.php @@ -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 ); } ),