Make WordPress Core

#46357 closed defect (bug) (fixed)

Don't prime site meta caches core functions

Reported by: spacedmonkey Owned by: flixos90
Milestone: 5.1.2 Priority: normal
Severity: normal Version: 5.1
Component: Networks and Sites Keywords: has-patch fixed-major
Focuses: multisite, performance Cc:


WP_Site_Query and get_sites are used in core functions to query the blogs table. As of 42836 site meta is in core and by default, primes the site meta caches on every WP_Site_Query call. However, in many places it is extremely unlikely the site meta will be required or used. For performance reasons, these calls that do not require site meta should be changed.

Attachments (1)

46357.diff (5.0 KB) - added by spacedmonkey 20 months ago.

Download all attachments as: .zip

Change History (10)

#1 @spacedmonkey
20 months ago

The following functions should be changed to not prime site meta caches

  • get_site_by_path
  • get_oembed_response_data_for_url
  • get_id_from_blogname
  • wp_update_network_site_counts
  • domain_exists
  • get_main_site_id
  • network/upgrade.php


  • get_blogs_of_user
  • get_blog_id_from_url
  • get_id_from_blogname

This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.

20 months ago

#3 @desrosj
20 months ago

  • Milestone changed from Awaiting Review to Future Release

20 months ago

#4 @spacedmonkey
20 months ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 5.1.2
  • Owner set to flixos90
  • Status changed from new to assigned

Added to 5.1.2 and assigning to @flixos90 for merge. More details #46167

#5 @flixos90
20 months ago

I think this is phrased incorrectly a little bit - if this is an enhancement, it shouldn't go into 5.1.x. However, it appears to be related to the bug #46167. Can you clarify how this is related? If this ticket indeed fixes a fatal error, it should probably be a "bug", not an "enhancement".

#6 @spacedmonkey
20 months ago

  • Type changed from enhancement to defect (bug)

This is a bug and enhancement at the same time.

The fixes the issue in #46167 as the error happens in function get_site_by_path that calls prime site meta before the check is loaded.

The two patches together work hand in hand, to make that queries are a not run on a none existing table, generating the error.

@flixos90 if 5.2 is landing soon, I am happy that it goes in that.

#7 @flixos90
20 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 44926:

Multisite: Do not prime site meta caches unless necessary.

Props spacedmonkey.
Fixes #46357. See #46167.

#8 @flixos90
20 months ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

#9 @flixos90
20 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 44928:

Multisite: Do not prime site meta caches unless necessary.

Merges [44926] to the 5.1 branch.

Props spacedmonkey.
Fixes #46357. See #46167.

Note: See TracTickets for help on using tickets.