[wp-trac] [WordPress Trac] #21760: get_term_by() calls are not cached
WordPress Trac
noreply at wordpress.org
Wed Sep 28 21:36:06 UTC 2016
#21760: get_term_by() calls are not cached
----------------------------------------+--------------------------
Reporter: wonderboymusic | Owner: ocean90
Type: enhancement | Status: assigned
Priority: normal | Milestone: 4.7
Component: Taxonomy | Version: 2.3
Severity: normal | Resolution:
Keywords: has-patch needs-unit-tests | Focuses: performance
----------------------------------------+--------------------------
Comment (by ocean90):
> ==== get_term_by( 'id' ) ====
>
> '''Before:'''
> > SELECT t.*, tt.* FROM wptests_terms AS t INNER JOIN
wptests_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id = 4"
>
> '''After:'''
> > SELECT t.*, tt.* FROM wptests_terms AS t INNER JOIN
wptests_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN
('category') AND t.term_id IN ( 4 ) LIMIT 1
The after query includes a check for the taxonomy which the before query
doesn't have.
Before patch: Tests_Term_GetTermBy->test_get_term_by_id, get_term_by,
get_term, WP_Term::get_instance
With [attachment:21760.7.patch]:
Tests_Term_GetTermBy->test_get_term_by_id, get_term_by, get_terms,
WP_Term_Query->query, WP_Term_Query->get_terms
If someone passes an ID to get_term_by() we can continue short-circuiting
the function and use `get_term()` directly like before. Done in
[https://github.com/aaronjorbin/develop.wordpress/pull/18/commits/25fa701d0fa5d6a0d900ddfd05b2292d78abd040
this commit].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/21760#comment:103>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list