r25386 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25385‎ | r25386 | r25387 >
Date:11:26, 1 September 2007
Author:daniel
Status:old
Tags:
Comment:
avoid filesort. downside: subcategories are more likely to be lost if categories and pages are listed together, and the limit is hit; that is, the limit is not applied to the list as displayed. This is counter-intuitive (kind of like the paging of subcategories on category pages)
Modified paths:
  • /trunk/extensions/CategoryTree/CategoryTreeFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php
@@ -183,8 +183,7 @@
184184 $page = $dbr->tableName( 'page' );
185185 $categorylinks = $dbr->tableName( 'categorylinks' );
186186
187 - $sql = "SELECT cat.page_namespace, cat.page_title,
188 - CASE WHEN cat.page_namespace=".NS_CATEGORY." THEN 0 ELSE 1 END AS presort
 187+ $sql = "SELECT cat.page_namespace, cat.page_title
189188 $transFields
190189 FROM $page as cat
191190 JOIN $categorylinks ON cl_from = cat.page_id
@@ -193,23 +192,29 @@
194193 $nsmatch
195194 "./*AND cat.page_is_redirect = 0*/"
196195 $transWhere
197 - ORDER BY presort, cl_sortkey
 196+ ORDER BY cl_sortkey
198197 LIMIT " . (int)$wgCategoryTreeMaxChildren;
199198
200199 $res = $dbr->query( $sql, __METHOD__ );
201200
202 - $s= '';
 201+ #collect categories separately from other pages
 202+ $categories= '';
 203+ $other= '';
203204
204205 while ( $row = $dbr->fetchRow( $res ) ) {
205 - #TODO: translation support; ideally added to Title object
206 - $t = Title::makeTitle( $row['page_namespace'], $row['page_title'] );
207 - $s .= $this->renderNode( $t, $mode, $depth>0, false, $depth-1 );
208 - $s .= "\n\t\t";
 206+ #TODO: translation support; ideally added to Title object
 207+ $t = Title::makeTitle( $row['page_namespace'], $row['page_title'] );
 208+
 209+ $s = $this->renderNode( $t, $mode, $depth>0, false, $depth-1 );
 210+ $s .= "\n\t\t";
 211+
 212+ if ($row['page_namespace'] == NS_CATEGORY) $categories .= $s;
 213+ else $other .= $s;
209214 }
210215
211216 $dbr->freeResult( $res );
212217
213 - return $s;
 218+ return $categories . $other;
214219 }
215220
216221 /**

Status & tagging log