[wp-trac] [WordPress Trac] #37189: In wp_term_query on cache ids

WordPress Trac noreply at wordpress.org
Thu Jun 22 02:27:28 UTC 2017


#37189: In wp_term_query on cache ids
--------------------------+--------------------------
 Reporter:  spacedmonkey  |       Owner:
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  4.9
Component:  Taxonomy      |     Version:  4.6
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  performance
--------------------------+--------------------------

Comment (by boonebgorges):

 [attachment:37189.4.patch] makes the following changes:

 * Cache key is now generated using a technique close to what @spacedmonkey
 originally suggested.
 * The cache is now populated by an array of `stdClass` objects (the raw
 results of the `get_results()` query). In most cases, it looks like this:
 `[ { term_id: 15 }, { term_id: 17 } ]`. In the case of
 `all_with_object_id`, it looks like this: `[ { term_id: 15, object_id: 123
 } ... ]`. Storing data like this means it's possible to share the same
 logic when populating `object_id` from the cache vs from a database query.
 I've also added a test demonstrating cache support for these queries.

 The second bullet point also means that I can drop the `stdClass` trick
 for `fields=ids`, since the results of `$wpdb->get_results( "SELECT
 term_id FROM ..." )` will be an array of `stdClass` objects. There's still
 the matter of ensuring that post-query processing later in the method
 doesn't attempt to operate on these items, but I feel that this little bit
 of maintenance overhead is worth the benefit of a true `fields=ids` query.

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


More information about the wp-trac mailing list