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

WordPress Trac noreply at wordpress.org
Wed Sep 28 19:27:58 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):

 This is a before/after overview for the SQL queries with
 [attachment:21760.5.patch]:

 ==== get_term_by( 'slug' ) ====

 '''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.slug = 'foo'
 AND tt.taxonomy = 'category' LIMIT 1

 '''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.slug = 'foo' ORDER BY t.name ASC


 ==== get_term_by( 'name' ) ====

 '''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.name = 'Foo'
 AND tt.taxonomy = 'category' LIMIT 1

 '''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.name IN ('Foo') ORDER BY t.name ASC

 ==== 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 ) ORDER BY t.name ASC

 ==== get_term_by( 'term_taxonomy_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
 tt.term_taxonomy_id = '5'  LIMIT 1"

 '''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.term_taxonomy_id = 5 ORDER BY t.name ASC LIMIT 1

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


More information about the wp-trac mailing list