[wp-trac] [WordPress Trac] #9661: cat_row doesn't not list all categories

WordPress Trac wp-trac at lists.automattic.com
Tue Apr 28 00:44:13 GMT 2009


#9661: cat_row  doesn't not list all categories
--------------------------+-------------------------------------------------
 Reporter:  hailin        |       Owner:  anonymous 
     Type:  defect (bug)  |      Status:  new       
 Priority:  normal        |   Milestone:  Unassigned
Component:  General       |     Version:            
 Severity:  normal        |    Keywords:            
--------------------------+-------------------------------------------------
 wp-admin/includes/template.php

 cat_rows and _cat_rows are buggy - it can not list all legitimate
 categories. The key reason is that within loop

 foreach ( $categories as $category )
   ...
   unset($categories[$i]) //Prune the working set

 We can not unset an element while the foreach loop is traversing the
 array, because it causes the internal PHP cursor to jump ahead, leaving
 out valid elements.  It's ok to unset an element as long as there is no
 outer loop performing on the array.

 Also, we should not try to get categories and children inside _cat_rows,
 instead, it's better to pass them in once and only once.

 If the page starts in a subtree, the original author forgot to assign
 $my_parent = get_category( $p ); so the subtree handling was not working
 at all.

 Overall, before and after my fix, the time complexity is O(N^2), so it's
 not efficient when # of categories reach 1000. However, I think reasonable
 range is at most a few hundreds. If speed becomes an issue, I suggest we
 use an O(N) algorithm, similar to that used in page_rows.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9661>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list