-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Settings: Prime options to reduce database queries #13700
Conversation
Size Change: 0 B Total Size: 2.77 MB ℹ️ View Unchanged
|
Plugin builds for 1080062 are ready 🛎️!
|
While reviewing this I noticed a few other places where we could optimize our database queries. Granted, this PR here makes such optimizations a bit redundant, as now they will all be primed. Thinking out loud, here's what I found: This call here causes a database query on every page load: web-stories-wp/includes/Story_Post_Type.php Line 133 in 0f96e44
Removing this call would require all sorts of changes to other classes depending on this default value. So probably not worth it. This call also causes a db query on every page load:
This is not something that the priming can address, as it's not our own option we're loading here. We can probably refactor to something like this: add_filter(
'googlesitekit_analytics-4_tag_amp_blocked',
function ( $blocked ) {
$handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER );
if ( 'web-stories' === $handler && $this->context->is_web_story() ) {
return true;
}
return $blocked;
}
);
add_action(
'web_stories_print_analytics',
function () {
$handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER );
if ( 'site-kit' === $handler && $this->is_analytics_module_active() ) {
remove_action( 'web_stories_print_analytics', [ $this->analytics, 'print_analytics_tag' ] );
}
},
5
); Another database query caused by this on every admin page: web-stories-wp/includes/Admin/Dashboard.php Line 240 in 0f96e44
which calls Potential solution: maybe split up On my local site I also noticed that a lot of options are autoloaded that probably shouldn't. Some countermeasures to consider:
|
Avoids early database calls
Avoids unnecessary database queries on other screens
Avoids database query by fetching plugin status information
OK that was quite the rabbit hole I went down here 😅 I found quite a few services that were being registered too early, causing unnecessary database queries. Also, some queries happened even before the priming happened. The Now there are indeed only the 2 expected database queries from the priming. |
Summary
This PR adds the use of
wp_prime_option_caches_by_group
to combine queries forweb-stories
related options on the dashboard.User-facing changes
None.
Testing Instructions
This PR can be tested by following these steps:
Reviews
Does this PR have a security-related impact?
No.
Does this PR change what data or activity we track or use?
No.
Does this PR have a legal-related impact?
No.
Checklist
Type: XYZ
label to the PRFixes #13523