Rebuild User Post Counts (query)

Subject Information

Category Name XenForo 2.x Tips and Guides
TOPIC TITLE Rebuild User Post Counts (query)
Thread starter AnimeHaxor
Start date
Replies
Views
First message reaction score
LAST MESSAGE BY AnimeHaxor

AnimeHaxor

Retro-NulledTeam
Staff member
Administrator
Moderator
Registered
Local time
6:28 PM
Joined
Nov 22, 2015
Messages
6,417
Reaction score
42,692
Points
113
Website
www.nullscripts.net
Site Script
XenForo
AnimeHaxor submitted a new resource:

Rebuild User Post Counts (query) - A quick and simple way to update post counts for users.

This is a query which updates user post counts. It takes into consideration moderated and deleted status of threads and posts, as well as each forum's "Count messages posted in this forum toward user total" setting.
Code:
UPDATE xf_user AS user SET message_count =
COALESCE(
 (
        SELECT COUNT(*)
        FROM xf_post AS post
        INNER JOIN xf_thread AS thread ON thread.thread_id = post.thread_id
        INNER JOIN xf_forum AS forum ON forum.node_id = thread.node_id
        WHERE...

Read more about this resource...