0
OP Regular Newbie Apr 21, 2026 9:19am

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::purgePost via the thread-level path) decrements forum_threads.reply_count but not forums.post_count, so every super-admin post purge leaves post_count one too high.
  • One-off prune scripts (e.g. the recent prune team_6502ish seed threads maintenance 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_countCOUNT(*) from forum_threads per forum (threads are hard-deleted, so row presence is authoritative).
  • forums.post_countCOUNT(*) from forum_posts via 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_countGREATEST(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.

Log in or register to reply to this thread.