[Liam W] (RIP) Post Count Rebuild

[Liam W] (RIP) Post Count Rebuild 2.0.3

No permission to download

Nirjonadda

Well-known member
@Liam W Rebuild user post counts, does this excluded from option Count messages posted in this forum toward user total? Also Please can add Cron entries for run automatically and re-check user total post count?

192821
 

Liam W

in memoriam 1998-2020
I'm not sure what you're asking? This add-on will respect that option, so any posts in those nodes will not be counted.

Liam
 

SeToY

Well-known member
Can this be used to upgrade from the XF1.5 version or is it recommended to remove the XF1.5 version beforehand?
 

ivp

Active member
It doesn't take into account whether posts/threads are visible.

Here is the fix:
Code:
$user->message_count = $this->app->finder('XF:Post')->where('user_id', $id)
	->where('Thread.Forum.count_messages', 1)->total();

should be replaced with:
Code:
$db = $this->app->db();
$user->message_count = $db->fetchOne("
	SELECT COUNT(*)
	FROM xf_post AS post
	LEFT JOIN xf_thread AS thread ON (thread.thread_id = post.thread_id)
	LEFT JOIN xf_forum AS forum ON (forum.node_id = thread.node_id)
	WHERE post.user_id = ?
	AND post.message_state = 'visible' AND thread.discussion_state = 'visible'
	AND forum.count_messages = 1
", $id);
 
Last edited:

Liam W

in memoriam 1998-2020
Just checked, and I changed this locally when adding support for a CLI rebuilder, but never released it 🤦🏻‍... whoops!
 

ivp

Active member
Many thanks for the update.

Both @Brogan and @Jake Bunce used LEFT JOIN instead of INNER JOIN, probably we should go that road:
 

Liam W

in memoriam 1998-2020
Brogan also filtered "AND forum.node_id IS NOT NULL" whereas the other one didn't. Wonder if it will make a difference.

It won't, actually, as this checks to ensure the forum counts messages, so if there is no forum defined for a post, then that value will be null, and will not match the condition.

It should also be noted that that condition was specifically intended to exclude orphaned threads, which was an XF1 bug and therefore should no longer be a major issue.
 

Liam W

in memoriam 1998-2020
Additionally, the use of INNER JOIN also prevents the existence of orphaned threads, as it requires that both the join columns exist for the row to be provided.
 
Top