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

WordPress Trac noreply at wordpress.org
Sat Mar 11 02:43:55 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:  needs-unit-tests needs-patch  |     Focuses:  performance
------------------------------------------+--------------------------
Changes (by boonebgorges):

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


Comment:

 @sstoqnov Thank you for the report and for the patch. You're right that
 this behavior is incorrect.

 Prior to the refactor in [38677], `get_term_by( 'name', '', 'post_tag' )`
 would always return false. Not because of a special case, as you suggest
 in [attachment:21760.11.patch], but because it'd result in a query like
 `SELECT ... WHERE name = ''`, and it's impossible to create a term
 (through `wp_insert_term()`, at least) with an empty string as `name` or
 `slug`.

 A blanket `empty( $value )` check is probably too broad, though. It'd
 cause failures in cases like the following: a term has the name `'0'`, and
 you try to fetch it using `get_term_by( 'name', '0', 'post_tag' )`. This
 kind of query is successful prior to [38677]. A more precise logic will
 probably convert 'name' or 'slug' `$value` to a string, and reject
 anything with 0 `strlen`, but this will need some unit tests. @sstoqnov
 Fancy writing some? :)

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


More information about the wp-trac mailing list