[wp-trac] [WordPress Trac] #14485: Didn't show up children category when created parent and children categories at the same time.

WordPress Trac wp-trac at lists.automattic.com
Sat Dec 11 06:34:08 UTC 2010


#14485: Didn't show up children category when created parent and children
categories at the same time.
--------------------------+-------------------------------------------------
 Reporter:  thealien      |       Owner:                          
     Type:  defect (bug)  |      Status:  new                     
 Priority:  high          |   Milestone:  3.1                     
Component:  Cache         |     Version:  3.0                     
 Severity:  normal        |    Keywords:  has-patch, needs-testing
--------------------------+-------------------------------------------------
Changes (by garyc40):

 * cc: garyc40@… (added)
  * keywords:  category,cache => has-patch, needs-testing


Comment:

 No, the bug hasn't been squashed yet.

 Patch attached.

 Related: #14399

 Root of the problem:

 Unique cache key for get_terms() is not created properly. It is a hash of
 term query concatenated with "last_changed" time. "last_changed" is
 currently created simply by generating the current timestamp time().

 However, when we insert many terms at once (with parent & child
 relationship), this "last_changed" key is still the same (all these
 operations are often within a fraction of a second). As a result, when
 get_terms() is called inside _get_term_hierarchy(), it always returns the
 same cache even though many new terms have been inserted.

 Another problem is with the static variable $cleaned in
 clean_term_cache(). When the parent term is created, $cleaned[$taxonomy]
 is set to true. When the child terms are created, $cleaned[$taxonomy] is
 already true, so the option "{$taxonomy}_children" is not properly
 regenerated.

 Solution is easy. I attached the ids of the created or changed terms
 inside last_changed key. clean_term_cache() is also made to accept another
 argument called $force_clean_taxonomy, when specified "true" will
 regenerate {$taxonomy}_children no matter what. When a children term is
 created, clean_term_cache($ids, $taxonomy, true, true) is called.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14485#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list