Actions
Bug #14909
closedReducing DB queries and asset loading on the main site
Status:
Resolved
Priority name:
Normal
Assignee:
Category name:
Performance
Target version:
Start date:
2021-10-27
Due date:
% Done:
0%
Estimated time:
Deployment actions:
Description
Since we are redesigning the homepage, it's a good opportunity to audit the number of database queries that run on the homepage (and the main site in general).
With the following code snippets, this can drop the DB query count by 11:
/** * Stop unnecessary DB queries for Classic Editor plugin. * * Classic Editor settings are only needed in the admin area. */ add_filter( 'classic_editor_plugin_settings', function( $retval ) { if ( is_admin() ) { return $retval; } return []; } ); // No need to check for mapped domain redirects on the main site. add_action( 'send_headers', function() { if ( is_main_site() ) { remove_action( 'send_headers', 'Mercator\Redirect\handle_redirect' ); } }, 0 ); // Only allow bbPress to initialize its roles on a group forum page. add_action( 'wp_roles_init', function() { if ( is_admin() ) { return; } /* * bbPress initializes its roles on every page load. * * This runs five uncached DB queries, so let's only enable this on group * forum pages where this might be necessary. */ if ( is_main_site() && false === strpos( $_SERVER['REQUEST_URI'], '/forum/' ) ) { remove_action( 'wp_roles_init', 'bbp_roles_init' ); } }, 0 );
Boone, I'm running this in wp-content/mu-plugins/ray.php
at the moment if you need to disable anything.
The Classic Editor and Mercator mods should be pretty straightforward. With the bbPress one, I briefly tested by logging in as a regular user and attempting to create a new group topic and this still worked fine.
Just wanted to post as a FYI. I'll add more improvements as I find them.
Actions