Cache Post Counts
WordPress and WooCommerce constantly want to know how many posts exist in each status: how many are published, how many are drafts, how many are pending, and so on. To work that out they run a COUNT query that scans wp_posts and groups by status. On a small site this is instant and nobody notices. On a large site with hundreds of thousands or millions of rows, that count is slow, and the real problem is that it runs constantly – every time you open the Posts or Products list screen, and every time you edit or add a post in the block editor. You end up paying for the same expensive scan over and over.
The Cache Post Counts option removes that repeated work. Scalability Pro keeps the count for each post type and status in its own small cache table, and hands those numbers to WordPress at the start of every request, so WordPress never runs the COUNT scan at all. That covers every place that asks for post counts: the Posts and Products list screens, the block editor (which counts your products every time you edit or add a post), and anything WooCommerce or another plugin works out from the same counts.
The counts stay exact. Every time a post or product is published, saved as a draft, trashed, restored or deleted, Scalability Pro adds one to the new status and takes one from the old status, in a single database update. There is no recount, so this stays fast however large the table gets, and it stays correct when several editors or an import are changing posts at the same time. You’ll find this in the Imports tab under “Cache Post Counts”. Turn it on and the caching applies straight away.
This exact, always-on behaviour is available since 6.47.0. Earlier versions only cached the list screens, and on WordPress 7 their cache stopped matching WordPress’s count query, so the option had no effect there.
Imports change thousands of posts at once, so Scalability Pro does not adjust the counts row by row while a WP All Import or Super Speedy Imports run is working: during the import, screens count the way WordPress normally does, and when the run finishes the stored counts are cleared, so the next screen counts once and the cache carries on from there. If an import is stopped part-way, normal caching resumes on its own within about ten minutes. If you use another tool that writes to wp_posts directly, the Clear Post Count Cache button on the same tab does the same thing, and the stored counts are refreshed daily anyway.
Two kinds of count are left to WordPress: order counts, which change constantly on a busy shop, and the counts shown to a user who cannot see other people’s private posts, because those include only that user’s own private posts and so differ from user to user.
If you are running large imports, this option pairs well with the wider import tuning in Diagnosing WP All Import Performance Issues with Scalability Pro. The related Cache Author and User Counts option handles the separate “Mine” and per-role counts on the same admin screens.
In short: WordPress recalculates post counts far more often than it needs to, and that scan gets expensive as your tables grow. Cache Post Counts keeps exact numbers in a cache table and gives them to WordPress before it asks, which speeds up the Posts and Products list screens and the block editor.
Comments