[wp-trac] [WordPress Trac] #29894: get_terms() isn't caching - duplicate queries generated
WordPress Trac
noreply at wordpress.org
Wed Oct 8 17:33:48 UTC 2014
#29894: get_terms() isn't caching - duplicate queries generated
-------------------------------+-----------------------------
Reporter: webgeekconsulting | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.0
Severity: normal | Keywords:
Focuses: performance |
-------------------------------+-----------------------------
get_terms() doesn't seem to be caching correctly and therefore generates
duplicate queries. In my plugin I have the following calls:
{{{
wp_dropdown_categories(array(
'taxonomy' => 'product_category',
'hide_empty' => 0,
'show_option_none' => __('Any', 'mp'),
'name' => 'child_of',
));
}}}
{{{
$cats = get_terms('product_category', array(
'hide_empty' => 0,
));
}}}
{{{
$cats = get_terms('product_category', array(
'hide_empty' => 0,
));
}}}
Yes, I realize I could technically create my own cache for the duplicate
get_terms() function, but no matter what I'll still have 2 queries due to
using wp_dropdown_categories() and get_terms() in the same request - even
though they generate the same query (see below).
{{{
SELECT t.*, tt.* FROM hf9v_terms AS t INNER JOIN hf9v_term_taxonomy AS tt
ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('product_category') ORDER
BY t.term_id ASC
include('wp-admin/admin-footer.php'), do_action('in_admin_footer'),
call_user_func_array, MP_Shortcode_Builder->display_short_code_form,
call_user_func,
MP_Shortcode_Builder->display_mp_list_categories_attributes,
wp_dropdown_categories, get_terms
}}}
{{{
SELECT t.*, tt.* FROM hf9v_terms AS t INNER JOIN hf9v_term_taxonomy AS tt
ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('product_category') ORDER
BY t.name ASC
include('wp-admin/admin-footer.php'), do_action('in_admin_footer'),
call_user_func_array, MP_Shortcode_Builder->display_short_code_form,
call_user_func,
MP_Shortcode_Builder->display_mp_list_categories_attributes,
get_categories, get_terms
}}}
{{{
SELECT t.*, tt.* FROM hf9v_terms AS t INNER JOIN hf9v_term_taxonomy AS tt
ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('product_category') ORDER
BY t.name ASC
include('wp-admin/admin-footer.php'), do_action('in_admin_footer'),
call_user_func_array, MP_Shortcode_Builder->display_short_code_form,
call_user_func, MP_Shortcode_Builder->display_mp_list_products_attributes,
get_terms
}}}
As you can see, the SQL statements are identical and therefore the db
should only be queried once.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29894>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list