Opened 10 years ago
Closed 8 years ago
#29942 closed defect (bug) (duplicate)
wp_get_object_terms - no caching mechanism in place - results in duplicate queries
Reported by: | webgeekconsulting | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.0 |
Component: | Taxonomy | Keywords: | needs-unit-tests has-patch |
Focuses: | performance | Cc: |
Description
wp_get_object_terms() isn't caching queries which results in duplicate queries against the database. See the following debug info:
SELECT t.term_id FROM hf9v_terms AS t INNER JOIN hf9v_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN hf9v_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('product_category') AND tr.object_id IN (229) ORDER BY t.name ASC include('wp-admin/edit-form-advanced.php'), do_meta_boxes, call_user_func, post_categories_meta_box, wp_popular_terms_checklist, wp_get_object_terms
SELECT t.term_id FROM hf9v_terms AS t INNER JOIN hf9v_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN hf9v_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('product_category') AND tr.object_id IN (229) ORDER BY t.name ASC include('wp-admin/edit-form-advanced.php'), do_meta_boxes, call_user_func, post_categories_meta_box, wp_terms_checklist, wp_get_object_terms
I've attached a patch that creates a cache of the database query - similar to what is being suggested in ticket #29894.
Attachments (1)
Change History (6)
#1
@
10 years ago
- Keywords needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
Thanks for the patch! As in #29894, I like the consolidation of cache keys. And as in #29894, I have a couple questions and concerns:
- It looks at a glance like the second query (2332 right hand side in https://core.trac.wordpress.org/attachment/ticket/29942/taxonomy.php.patch) is pulling up information that is available in the main query being fired earlier. No need for a second query, and no need for a separate cache. This needs testing.
- Unit test coverage for
wp_get_object_terms()
is pretty lackluster. I'm very wary of making these sorts of changes until we at least get basic coverage.
#3
@
8 years ago
Just run into this again, if there's anyone out there who wants to put a little time into digging into Taxonomies, this could be an interesting patch to continue with @boonebgorges concerns :)
Note: See
TracTickets for help on using
tickets.
taxonomy.php patch