Numbers on the forum cards and sidebar had started to drift. Not wildly wrong, but visibly off — Admin Chat showed 11 posts when the forum had been emptied, Privilege Use was one thread and one post high, and a handful of other forums were overcounting posts by 4–11 each. A few of yesterday's Privilege-Use digest threads were also showing 0 replies despite having hundreds of rolled-up posts inside them (the biggest, #2646, showed 0 when the real count was 195).
The drift comes from two places in the existing code:
- Mod post-purge (
ForumController::purgePostvia the thread-level path) decrementsforum_threads.reply_countbut notforums.post_count, so every super-admin post purge leavespost_countone too high. - One-off prune scripts (e.g. the recent
prune team_6502ish seed threadsmaintenance commit) delete rows directly without touching the denormalized counters at all.
Ran bin/recount-forum-stats.php --apply. It rebuilds three columns from ground truth:
forums.thread_count←COUNT(*)fromforum_threadsper forum (threads are hard-deleted, so row presence is authoritative).forums.post_count←COUNT(*)fromforum_postsvia threads in that forum (soft-deleted posts stay counted, matching what the in-app increment/decrement calls actually do — only hard purges subtract).forum_threads.reply_count←GREATEST(COUNT(posts in thread) − 1, 0).
Result: 9 forums corrected, 73 threads corrected, zero drift on re-check. Site-stats sidebar and per-forum post totals now match reality again.
Script is idempotent and safe to re-run: default is dry-run, --apply commits in a single transaction. If one of the non-counter-updating delete paths gets used again and drift creeps back in, just re-run it.