Make WordPress Core

Opened 2 years ago

Closed 20 months ago

Last modified 20 months ago

#55802 closed defect (bug) (fixed)

Store main site of network in network options

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.1 Priority: normal
Severity: normal Version: 4.9
Component: Networks and Sites Keywords: has-patch has-unit-tests has-dev-note
Focuses: multisite, performance Cc:

Description

Instead of doing a live lookup for main site on network in WP_Network class, store / cache the value in network options, to save a database lookup.

Change History (15)

This ticket was mentioned in PR #2995 on WordPress/wordpress-develop by spacedmonkey.


23 months ago
#1

  • Keywords has-patch added; needs-patch removed

#2 @spacedmonkey
21 months ago

  • Keywords has-unit-tests added
  • Milestone changed from Awaiting Review to 6.1

#3 @johnjamesjacoby
21 months ago

Left some thoughts on the PR.

I am a big +1 on this being a 6.1 change.

It is very small & obvious win, and will always be an improvement over the existing/previous approach. 👍

spacedmonkey commented on PR #2995:


21 months ago
#4

Should we add 'main_site' => '0' to populate_network_meta() so that every newly populated network has that meta key? This way, it always exists, and any 'meta|option' calls to it will not be cache misses?

There will not be a cache miss, as with the change to use metadata api, no database query is run on a miss. Which is neat. I think it is a good thing. It should populate it's self. But maybe we need something on network upgrade.

Does update_user_meta() have the potential to alter $wpdb->insert_id if the meta does not exist? If so, should it use $current_site->blog_id instead of $wpdb->insert_id? Is that maybe safer/more-clear either way?

Good catch. Add code suggestion.

@JJJ Any idea why the unit tests are failing?

JJJ commented on PR #2995:


21 months ago
#5

Any idea why the unit tests are failing?

No, actually! I did look into it for about an hour this morning.

The only possible anomaly I discovered is that the multisite tests are passing with PHP versions 8.1 & 8.2 – maybe it is related to changes in parse_url() and not directly related to changes in this PR?

spacedmonkey commented on PR #2995:


20 months ago
#6

No, actually! I did look into it for about an hour this morning.

The only possible anomaly I discovered is that the multisite tests are passing with PHP versions 8.1 & 8.2 – maybe it is related to changes in parse_url() and not directly related to changes in this PR?

@JJJ Thanks for looking into this. It seems like the tests are passing just fine now. So might be completely unreleated

spacedmonkey commented on PR #2995:


20 months ago
#7

I wonder if we should also save the main site id, on database upgrade.

#8 @spacedmonkey
20 months ago

After a chat @desrosj, decided to merge this. We can revert after beta.

#9 @spacedmonkey
20 months ago

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

In 54256:

Networks and Sites: Store main site id of a network in network options.

Instead of caching main site id an object cache, store main site id on a network options. This results in less database queries on sites without persistent object caching.

Props spacedmonkey, johnjamesjacoby, peterwilsoncc, desrosj.
Fixes #55802.

spacedmonkey commented on PR #2995:


20 months ago
#10

Committed into core.

JJJ commented on PR #2995:


20 months ago
#11

Tangentially, I really like how this cascades though get_network() and get_main_site_id() ⭐️🤟

#12 @milana_cap
20 months ago

  • Keywords add-to-field-guide added

#13 @spacedmonkey
20 months ago

Made a start on the dev note here.

#14 @milana_cap
20 months ago

  • Keywords needs-dev-note added; add-to-field-guide removed
Note: See TracTickets for help on using tickets.