WordPress.org

Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #37094, comment 5


Ignore:
Timestamp:
06/18/2017 12:54:27 PM (4 years ago)
Author:
boonebgorges
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37094, comment 5

    initial v1  
    44What @ocean90 is seeing is not errors, but the results of `EXPLAIN`, which indicate that a move to `get_posts()` forces `Using temporary`. This is bad, and gets increasingly bad as the site of your posts and term_relationships tables get bigger. The main ID query in `get_posts()` often has to use temporary tables when `tax_query` is used, mostly because `GROUP BY` is needed to ensure uniqueness (the same post could match more than one of the terms). There is no easy way to fix this, and given that this part of `WP_Query` has no caching at all, I'm not convinced that there's a benefit to switching to `get_posts()` here; there may in fact be a loss in performance.
    55
    6 That being said, it is a good idea to improve performance here. How about adding caching to `get_objects_in_term()`? [attachment:37094.diff] shows how this can be done. This actually has bigger impact on query reduction than the original patch, since `get_objects_in_term()` is used more broadly, while `get_posts()` always requires at least one query. Tests are also attached that show invalidation when: (a) term assignment changes, (b) a term is deleted, (c) a post is deleted. Thoughts?
     6That being said, it is a good idea to improve performance here. How about adding caching to `get_objects_in_term()`? [attachment:37094.diff] shows how this can be done. This actually has bigger impact on query reduction than the original patch, since `get_objects_in_term()` is used more broadly, while `get_posts()` always requires at least one query. Tests are also attached that show invalidation when: (a) term assignment changes, (b) a term is deleted, (c) a post is deleted. (No invalidation exists when deleting a non-post object type, but presumably this ought to be handled by the plugin registering the non-post taxonomy.) Thoughts?
     7
     8Side note that caching for `get_objects_in_term()` was suggested and sorta rejected in https://core.trac.wordpress.org/ticket/27120#comment:9. But the "switched to a higher level function" idea there probably corresponds to @spacedmonkey's original idea on this ticket, which is less than ideal for the reasons described above. For these reasons I think that caching `get_objects_in_term()` is a reasonable way forward.