From: Roan Kattouw Date: Tue, 13 May 2008 10:39:01 +0000 (+0000) Subject: (bug 14012) prop=templates filesorts under some conditions X-Git-Tag: 1.31.0-rc.0~47674 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=3ca55a03ad9df6b5d5bfc0447d9fe1bd9bbea32e;p=lhc%2Fweb%2Fwiklou.git (bug 14012) prop=templates filesorts under some conditions --- diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php index 5a2cf07441..b27be256ee 100644 --- a/includes/api/ApiQueryLinks.php +++ b/includes/api/ApiQueryLinks.php @@ -84,7 +84,18 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { $this->addTables($this->table); $this->addWhereFld($this->prefix . '_from', array_keys($this->getPageSet()->getGoodTitles())); $this->addWhereFld($this->prefix . '_namespace', $params['namespace']); - $this->addOption('ORDER BY', str_replace('pl_', $this->prefix . '_', 'pl_from, pl_namespace, pl_title')); + + # Here's some MySQL craziness going on: if you use WHERE foo='bar' + # and later ORDER BY foo MySQL doesn't notice the ORDER BY is pointless + # but instead goes and filesorts, because the index for foo was used + # already. To work around this, we drop constant fields in the WHERE + # clause from the ORDER BY clause + $order = array(); + if(count($this->getPageSet()->getGoodTitles()) != 1) + $order[] = "{$this->prefix}_from"; + // pl_namespace is always constant + $order[] = "{$this->prefix}_title"; + $this->addOption('ORDER BY', implode(", ", $order)); $db = $this->getDB(); $res = $this->select(__METHOD__);