Recently worked a WordPress site where the admin dashboard was taking a minute or more to load. Tracked the problem to the “Updates Needed” section in the “WordFence” block displayed on the dashboard. The Updates Needed section calls the WordPress “wp_version_check()” function. This function, as part of building the data sent to wordpress.org with the update version check, calls the WordPress “count_users()” function. The “count_users()” function runs a query like this:
|
SELECT COUNT(NULLIF(`meta_value` LIKE ?, false)), COUNT(NULLIF(`meta_value` LIKE ?, false)), COUNT(NULLIF(`meta_value` LIKE ?, false)), COUNT(NULLIF(`meta_value` LIKE ?, false)), COUNT(NULLIF(`meta_value` LIKE ?, false)), COUNT(NULLIF(`meta_value` LIKE ?, false)), COUNT(NULLIF(`meta_value` LIKE ?, false)), COUNT(NULLIF(`meta_value` LIKE ?, false)), COUNT(NULLIF(`meta_value` LIKE ?, false)), COUNT(NULLIF(`meta_value` = ?, false)), COUNT(*) FROM wp_usermeta INNER JOIN wp_users ON user_id = ID WHERE meta_key = ? |
The number of “COUNT(NULLIF” columns depends on the number of user groups. For a site with a small number of users and groups this query is not a problem. But for a site with over 100K users this query took over 100 seconds to run.
To fix the problem, we used “wp-cli” to disable the “Updates Needed” section in WordFence:
|
wp db query "update wp_wfConfig set val = 0 where name = 'notification_updatesNeeded';" |
Now the admin dashboard loads with no delay. This is a great example of the types of problems that come with scaling a WordPress site to large numbers of users.