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

WordPress Trac noreply at wordpress.org
Fri Mar 10 13:45:52 UTC 2017


#21760: get_term_by() calls are not cached
-------------------------------------------------+-------------------------
 Reporter:  wonderboymusic                       |       Owner:  ocean90
     Type:  enhancement                          |      Status:  reopened
 Priority:  normal                               |   Milestone:  4.8
Component:  Taxonomy                             |     Version:  2.3
 Severity:  major                                |  Resolution:
 Keywords:  has-patch needs-refresh needs-unit-  |     Focuses:
  tests                                          |  performance
-------------------------------------------------+-------------------------
Changes (by sstoqnov):

 * keywords:  has-patch has-unit-tests => has-patch needs-refresh needs-
     unit-tests
 * severity:  normal => major


Comment:

 Hi everybody.

 I found a small bug, when I was trying to fix this issue.
 https://github.com/Automattic/jetpack/issues/6607
 When we add an empty `$value`, the response is always the tag with the
 lowest term_id.

 I dig a bit more deeper and I found that `WP_Term_query->get_terms` method
 checks is the value is empty and doesn't add the `where` clause if it's (
 https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-
 term-query.php#L477 )

 Here is an example queries:

 >> When we have value
 > SELECT  t.*, tt.* FROM test_terms AS t  INNER JOIN test_term_taxonomy AS
 tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('post_tag') AND t.name
 IN ('test')  LIMIT 1

 >> When the value is empty
 >SELECT  t.*, tt.* FROM test_terms AS t  INNER JOIN test_term_taxonomy AS
 tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('post_tag')  LIMIT 1

 As you can see the `AND t.name IN ('test')` is missing from second
 request.
 [https://core.trac.wordpress.org/attachment/ticket/21760/21760.11.patch
 21760.11.patch] fix this issue.

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


More information about the wp-trac mailing list