[wp-trac] [WordPress Trac] #57326: get_blog_details() cache misses

WordPress Trac noreply at wordpress.org
Wed Dec 14 03:16:26 UTC 2022


#57326: get_blog_details() cache misses
--------------------------------+-----------------------------
 Reporter:  dd32                |      Owner:  (none)
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Networks and Sites  |    Version:
 Severity:  normal              |   Keywords:
  Focuses:  multisite           |
--------------------------------+-----------------------------
 `get_blog_details()` has multiple confusing cache groups included, under
 certain circumstances it's possible to get in a state where it will always
 trigger a SQL query.

 With the input of `get_blog_details( [ 'domain' => 'example.org', 'path'
 => '/' ] );` it'll first check the `blog-lookup` cache and return that
 data.

 If not, it'll then perform a SQL to get the blog_id.
 With that blog_id, it'll then check the `blog-details` cache, and return
 that data if it exists.

 If that cache is empty, it'll retrieve the details ultimately setting both
 the `blog-details` and `blog-lookup` caches.

 In the event that the `blog-lookup` cache is empty, but the `blog-details`
 cache is set (For example, using an external object cache where keys may
 be purged) the first SQL query will be triggered on every call until the
 `blog-details` cache expires.

 The attached PR will cover that case by setting that cache-key again when
 it's unset.

 Additionally, With the input of `get_blog_details( [ 'domain' =>
 'example.org' ] );` it'll perform a cache check of the `blog-lookup` cache
 with the md5 of the domain only, no path specified. As we always set the
 cache with a path component (even just `/`) this cache check will never
 match.
 Unfortunately with the input of only a domain, the lookup is NOT
 restricted to `/` so we realistically can't just include the root path by
 default. The return value is also ambiguous in this case as no `ORDER BY`
 is specified and subdomain installs can still have multiple sites on a
 single domain.

 The attached PR resolves this by conditionally setting the `blog-lookup`
 cache when the request being made is specifically for a domain and no
 path.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57326>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list