[wp-trac] [WordPress Trac] #32044: is_object_in_term() leaks DB queries
WordPress Trac
noreply at wordpress.org
Fri Apr 24 19:49:05 UTC 2015
#32044: is_object_in_term() leaks DB queries
------------------------------------------+--------------------
Reporter: joehoyle | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.3
Component: Taxonomy | Version: 4.1.1
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+--------------------
Changes (by boonebgorges):
* keywords: 4.3-early => needs-patch needs-unit-tests
* milestone: Future Release => 4.3
Comment:
I've looked a little more into this. A couple takeaways:
- We can't use `get_the_terms()`. It assumes that the object type is a
post type, while `is_object_in_term()` should be object_type-agnostic.
- The easiest thing to do is to tear cache support out of the function :)
- `get_object_term_cache()` requires object ids and a taxonomy name.
`update_object_term_cache()` requires object IDs and an *object type*.
When we're inside of `is_object_in_term()`, we don't have access to object
types, which is why we can't use `update_object_term_cache()` to prime the
cache at this point.
- This all points to the fact that our cache support for term
relationships is pretty lousy. A proper fix would be to add support to
`wp_get_object_terms()`. This will probably require modifying
`update_object_term_cache()` so that you can pass in an array of
taxonomies, rather than relying on `get_object_taxonomies()`. This will be
a fair bit of work, but it will result in broader performance
improvements. However, the fact that `wp_get_object_terms()` does not have
cache support is semi-famous in the WP world, so I'll have to do some more
research into the back story of why that's the case.
I'm going to move this into the 4.3 milestone for further investigation.
Worst case, we should at least make `is_object_in_term()` more consistent.
But maybe we can use this as an excuse to fix term-relationship caches for
real.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32044#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list