[wp-trac] [WordPress Trac] #21760: get_term_by() calls are not cached

WordPress Trac noreply at wordpress.org
Mon Dec 15 07:22:30 UTC 2014


#21760: get_term_by() calls are not cached
----------------------------+-----------------------------
 Reporter:  wonderboymusic  |       Owner:  wonderboymusic
     Type:  enhancement     |      Status:  reopened
 Priority:  normal          |   Milestone:  4.1
Component:  Taxonomy        |     Version:  2.3
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |     Focuses:
----------------------------+-----------------------------
Changes (by nacin):

 * status:  closed => reopened
 * resolution:  fixed =>


Comment:

 This most likely broke something on .com (whether they know about it yet
 or not) and in some plugins that mess directly with term caches. But it's
 not just that.

 First, the pedantic stuff I've previously covered: We cannot change the
 group names like this. If we could, we could have abandoned 'post_tag',
 'category', and $taxonomy a long time ago. We can likely change $taxonomy
 to "taxonomy-$taxonomy" or just 'taxonomy' or 'term' (proposed either here
 or elsewhere).

 (I wrote two years ago on this ticket: "we'll need to keep the standard
 category, post_tag, and link_category buckets, but we should be able to
 get away with prefixing the buckets of any custom taxonomy.")

 Here's how I would expect last_changed to be used:
  * The term 1, name Apple, slug apple, is saved.
  * A term object is cached with key = 1, value = object, group = 'term'
 (or similar)
  * A term slug is cached with key = apple, value = 1 (ID), group =
 'termslugs' (or similar)
  * A term name is cached with key = 'Apple', value = 1 (ID), group =
 'termnames' (or similar)
  * The key last_changed for the group 'term' is set to "0.51245500
 1418627718" (microtime())
  * get_terms() caches its queries. When doing so, it includes the value of
 last_changed in its cache key

 Later, this term is updated:
  * The caches for 1 (group term), apple (group termslugs), Apple (group
 termnames) are deleted
  * The new object, slug, and name are set into cache
  * last_changed is bumped, and get_terms()'s cache is invalidated

 As it stands now, whenever any term is edited, every term's cache gets
 completely wiped out. That seems like it's worse than it was previously.
 What am I missing?

 Additionally, what's in trunk now actually makes a lot of code redundant
 or useless. What's the point of `wp_cache_delete($term->term_id,
 $term->taxonomy);` when that's no longer the name of the group, and any
 change invalidates everything everywhere? Does clean_term_cache() even
 work anymore? It doesn't look like it does. That's a problem and it's
 going to break things.

 At this point, I think we need to revert this from the branch and try
 again in 4.2.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/21760#comment:72>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list