EddieGP has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/343805 )
Change subject: Follow-up Improve sorting on SpecialWanted*-Pages ...................................................................... Follow-up Improve sorting on SpecialWanted*-Pages Change the SpecialWanted*-Pages so that they do sort 1. by the number of links to a site (as is now) and 2. alphabetically for entries which have the same number of links (new) This is a follow-up for Change-Id If54cd5, commit 5b15728 The previous patch was reverted because using getOrderFields and prefixing each order field with qc_ in fetchFromCache threw DB errors in production. This follow-up differs in introducing a new function fetchCacheUseOrder that returns false by default and thus keeps the known behaviour. No SQL query is changed from how it is generated right now unless a subclass has an override for fetchCacheUseOrder. Bug: T4335 Change-Id: Ic01a3c28892c78ba9a9f0a7d665937efe87b44bd --- M includes/specialpage/QueryPage.php M includes/specialpage/WantedQueryPage.php 2 files changed, 57 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/05/343805/1 diff --git a/includes/specialpage/QueryPage.php b/includes/specialpage/QueryPage.php index 65e82e8..2eec331 100644 --- a/includes/specialpage/QueryPage.php +++ b/includes/specialpage/QueryPage.php @@ -407,7 +407,7 @@ $options = isset( $query['options'] ) ? (array)$query['options'] : []; $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : []; - if ( count( $order ) ) { + if ( $order ) { $options['ORDER BY'] = $order; } @@ -460,23 +460,45 @@ if ( $limit !== false ) { $options['LIMIT'] = intval( $limit ); } + if ( $offset !== false ) { $options['OFFSET'] = intval( $offset ); } - if ( $this->sortDescending() ) { - $options['ORDER BY'] = 'qc_value DESC'; + + $DESC = $this->sortDescending() ? ' DESC' : ''; + if ( $this->fetchCacheUseOrder() ) { + $orderFields = $this->getOrderFields(); + $order = []; + foreach ( $orderFields as $field ) { + $order[] = "qc_{$field}{$DESC}"; + } + if ( $order ) { + $options['ORDER BY'] = $order; + } } else { - $options['ORDER BY'] = 'qc_value ASC'; + $options['ORDER BY'] = "value{$DESC}"; } + return $dbr->select( 'querycache', [ 'qc_type', 'namespace' => 'qc_namespace', 'title' => 'qc_title', 'value' => 'qc_value' ], [ 'qc_type' => $this->getName() ], - __METHOD__, $options + __METHOD__, + $options ); } + /** + * Return whether to use the order fields returned by getOrderFields + * when running fetchFromCache or to always use "ORDER BY value" which + * was the default prior to this function. + * @return bool + */ + function fetchCacheUseOrder() { + return false; + } + public function getCachedTimestamp() { if ( is_null( $this->cachedTimestamp ) ) { $dbr = wfGetDB( DB_REPLICA ); diff --git a/includes/specialpage/WantedQueryPage.php b/includes/specialpage/WantedQueryPage.php index 9d92cbd..4da90ee 100644 --- a/includes/specialpage/WantedQueryPage.php +++ b/includes/specialpage/WantedQueryPage.php @@ -119,4 +119,34 @@ $label = $this->msg( 'nlinks' )->numParams( $result->value )->escaped(); return Linker::link( $wlh, $label ); } + + /** + * Order by title, overwrites QueryPage::getOrderFields + * + * @return array + */ + function getOrderFields() { + return [ 'value DESC', 'namespace', 'title' ]; + } + + /** + * Do not order descending for all order fields. We will use DESC only on one field, see + * getOrderFields above. This overwrites sortDescending from QueryPage::getOrderFields(). + * Do NOT change this to true unless you remove the phrase DESC in getOrderFiels above. + * If you do a database error will be thrown due to double adding DESC to query! + * + * @return bool + */ + function sortDescending() { + return false; + } + + /** + * Also use the order fields returned by getOrderFields when fetching from the cache. + * @return bool + */ + function fetchCacheUseOrder() { + return true; + } + } -- To view, visit https://gerrit.wikimedia.org/r/343805 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic01a3c28892c78ba9a9f0a7d665937efe87b44bd Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: EddieGP <wikimedia....@eddie-sh.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits