[wp-trac] [WordPress Trac] #42252: Use more granular caching for common queries in `WP_Site_Query`

WordPress Trac noreply at wordpress.org
Sat Nov 18 00:17:41 UTC 2017


#42252: Use more granular caching for common queries in `WP_Site_Query`
----------------------------------------+------------------------
 Reporter:  flixos90                    |       Owner:  flixos90
     Type:  enhancement                 |      Status:  assigned
 Priority:  normal                      |   Milestone:  5.0
Component:  Networks and Sites          |     Version:
 Severity:  normal                      |  Resolution:
 Keywords:  needs-unit-tests has-patch  |     Focuses:  multisite
----------------------------------------+------------------------
Changes (by flixos90):

 * keywords:  needs-patch needs-unit-tests => needs-unit-tests has-patch
 * owner:   => flixos90
 * status:  new => assigned


Comment:

 I like the more dynamic approach for the creation of the
 `$last_changed_prefix` that @spacedmonkey suggested in his updates, and
 having support for `$network_id` as its own "group" totally makes sense.

 In [attachment:42252.5.diff] I made the following changes:

 * The logic for creating a special `last_changed` prefix is a bit more
 flexible: Now ''any'' kind of permutation of the `domain`, `path` and
 `network_id` arguments or subset (as sole arguments of course) will
 determine a special prefix. By iterating through the arguments in a
 predefined order, it is ensured that there is only one key for the same
 argument values.
 * The logic in `clean_blog_cache()` has been adjusted so that it clears
 all possibly relevant `last_changed` caches. The most complicated part to
 figure out here was how to reliably create all relevant subsets to clear,
 but eventually I found https://gist.github.com/christophervalles/1066801
 to help me out.
 * Both the logic in `WP_Site_Query::get_cache_key()` and
 `clean_blog_cache()` ensure that all relevant values before serializing
 are parsed into strings (in case they aren't already). This is necessary
 to ensure that they can be reliably cleared (think about for example
 `$network_id` which may be a string or integer).
 * The `$ignore_args` array (containing arguments which are irrelevant for
 determining a `last_changed` value) is brought back, any particular
 concerns why you stripped that out in your patch @spacedmonkey?

 With this current behavior, the only regarding the arguments we'd need to
 worry about in the future is to keep them in sync between
 `WP_Site_Query::get_cache_key()` and `clean_blog_cache()`.

 Still much needed are unit tests, which I will work on in the next week or
 two. Let's of course keep continuing to discuss the approach and patch in
 the meantime.

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


More information about the wp-trac mailing list