#55802 closed defect (bug) (fixed)
Store main site of network in network options
Reported by: | spacedmonkey | Owned by: | 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.
2 years ago
#1
- Keywords has-patch added; needs-patch removed
#3
@
2 years 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:
2 years 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?
2 years 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:
2 years 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:
2 years ago
#7
I wonder if we should also save the main site id, on database upgrade.
spacedmonkey commented on PR #2995:
2 years ago
#10
Committed into core.
2 years ago
#11
Tangentially, I really like how this cascades though get_network()
and get_main_site_id()
⭐️🤟
Trac ticket: https://core.trac.wordpress.org/ticket/55802