Make WordPress Core

#57326 closed defect (bug) (duplicate)

get_blog_details() cache misses

Reported by: dd32's profile dd32 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: has-patch has-unit-tests
Focuses: multisite Cc:

Description

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.

Change History (4)

This ticket was mentioned in PR #3746 on WordPress/wordpress-develop by @dd32.


21 months ago
#1

  • Keywords has-patch has-unit-tests added

This ticket was mentioned in PR #3747 on WordPress/wordpress-develop by @dd32.


21 months ago
#2

This started out as #3746 and instead forked to use get_blog_id_from_url() instead of the custom SQL and duplicative cache group.
get_blog_id_from_url() uses the blog-id-cache group which is covered by tests.

Trac ticket: https://core.trac.wordpress.org/ticket/57326

#3 @dd32
21 months ago

After getting https://github.com/WordPress/wordpress-develop/pull/3746 to pass, I decided to strip out the custom code in favour of a different function, get_blog_id_from_url().

By passing '' as the $path the domain-only branch may change it's return value, as it's gone from a non-ordered-sql to using a deterministic ORDER BY id ASC. Under most situations, these should return the same data.. unless the records in the database table were inserted in a different order.

Needs review from someone more familiar with Multisite caching :)

#4 @spacedmonkey
21 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #40228.

Note: See TracTickets for help on using tickets.