Nikola Smolenski wrote:
I have made a patch which enables display of all
articles that belong to
multiple categories.
I think the following patch is slightly more efficient.
The database query itself is very inefficient though. If this was Perl,
I could make it way more efficient. In short, the "DISTINCT" and "ORDER
BY" are performance killers. They should be done in PHP instead.
Timwi
Index: includes/Parser.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/Parser.php,v
retrieving revision 1.135
diff -u -r1.135 Parser.php
--- includes/Parser.php 15 May 2004 00:29:07 -0000 1.135
+++ includes/Parser.php 29 Jun 2004 22:34:32 -0000
@@ -318,7 +318,25 @@
# FIXME: add limits
$t = wfStrencode( $this->mTitle->getDBKey() );
- $sql = "SELECT DISTINCT cur_title,cur_namespace FROM cur,categorylinks WHERE
cl_to='$t' AND cl_from=cur_id ORDER BY cl_sortkey" ;
+ $t = preg_replace("'/+'","/",$t);
+ if(strchr($t,"/")) {
+ $ta = explode("/",$t);
+ $tt = "cur c";
+ $tw = "";
+
+ $i = 0;
+ foreach($ta as $v) {
+ $tt .= ", categorylinks cl$i";
+ if ($tw != "") { $tw .= " AND "; }
+ $tw .= "cl$i.cl_to='$v' AND cl$i.cl_from=c.cur_id";
+ $i++;
+ }
+ $sql = "SELECT DISTINCT c.cur_title, c.cur_namespace FROM $tt " .
+ " WHERE $tw ORDER BY cl0.cl_sortkey";
+ } else {
+ $sql = "SELECT DISTINCT c.cur_title, c.cur_namespace FROM cur c, categorylinks cl
" .
+ " WHERE cl.cl_to='$t' AND cl.cl_from=c.cur_id ORDER BY
cl.cl_sortkey" ;
+ }
$res = wfQuery ( $sql, DB_READ ) ;
while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;