[wp-trac] [WordPress Trac] #29894: get_terms() isn't caching - duplicate queries generated

WordPress Trac noreply at wordpress.org
Thu Oct 9 02:15:00 UTC 2014


#29894: get_terms() isn't caching - duplicate queries generated
------------------------------------------+-----------------------------
 Reporter:  webgeekconsulting             |       Owner:  boonebgorges
     Type:  defect (bug)                  |      Status:  accepted
 Priority:  normal                        |   Milestone:  Future Release
Component:  Taxonomy                      |     Version:  4.0
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:  performance
------------------------------------------+-----------------------------

Comment (by webgeekconsulting):

 Replying to [comment:10 boonebgorges]:
 > webgeekconsulting - Thanks - I'm not sure that update3.diff is the
 entire patch you meant to attach, but I can see enough to understand what
 you're suggesting.
 >
 > After further thought, it appears that using merely the SQL to generate
 a cache key is not going to work. `get_terms()` returns different kinds of
 values depending on the value of the 'fields' parameter, but these
 different values come from the same database query. Using the SQL alone to
 create a cache key isn't fine-grained enough.
 >
 > I think we have to go with a more conservative approach here. Let's keep
 using the `$args` array to generate the cache key, but let's typecast all
 of the cache keys as necessary. Eg:
 >
 > {{{
 > $args['hide_empty'] = (bool) $args['hide_empty'];
 > }}}
 >
 > and so on, with all of the relevant arguments. However, I don't think we
 can safely make these kinds of changes without more complete unit tests,
 because there are places in the function where loose typing is expected -
 see eg https://core.trac.wordpress.org/browser/tags/4.0/src/wp-
 includes/taxonomy.php#L1290.
 >
 > I'm attaching a simple unit test that demonstrates the problem as
 originally reported.
 That's a great point which leads me to another possible solution...

 What if we were to create an object cache of the underlying query itself?
 Then, repeat calls to get_terms() that would use the same query, but use
 the data differently (e.g. the fields parameter) would use use the object
 cache instead of another query against the database.

 If that sounds like something that work, I'll upload another patch
 tomorrow with these changes.

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


More information about the wp-trac mailing list