Only run 'SHOW TABLES' install check when an administrator is on the Dashboard #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
S2_Core::s2init()
method, which runs at'plugins_loaded'
on every pageload, performs aSHOW TABLES LIKE ...
query in order to see whether installation is required.This frequent query is problematic. On installations with many database tables, such as a large Multisite installation,
SHOW TABLES LIKE ...
queries can take a long time to execute. For example, on the client site where I noticed this issue, with around 15,000 sites,SHOW TABLES LIKE...
queries can take more than half a second to complete.Moreover, this particular check is to see whether installation is necessary. In theory, installation should never be necessary, except the very first pageload after activation. So the query is unnecessary in the vast majority of cases.
There are a couple of ways to work around this:
version
flag like you do for the upgrade routine.$wpdb->get_var( "SELECT id FROM wp_subscribe2 ORDER BY ID DESC LIMIT 1" )
, which would check for the first entry in thewp_subscribe
table (perhaps you could have a placeholder entry so that it always returns an item if the table exists)The first three options seem like they're worth exploring. But I've opted to send a pull request that uses the last option, because it requires the least amount of code changes. I'm limiting the query to pageloads by someone with the
manage_options
capability, when viewing wp-admin. This doesn't solve the problem generally, but it does prevent the worst of the performance issues.