Current Behavior
Post count increases by one for Post Events, counted after post is made following the post event. See this thread on discuss for more information and demonstration links.
Steps to Reproduce
Expected Behavior
In step 5, post count should only reflect previous count + 1, post events should not count
Screenshots
If applicable, add screenshots to help explain your problem.
Environment
The issue seems to be that comments_count includes all types of posts, not only comments.
Thus actions like renaming a discussion are included in the count.
https://github.com/flarum/core/blob/master/src/User/User.php#L756
Honestly why is there comment_count and discussion_count while you can get the count from the relationships 馃
Performance and DB load, basically. Sometimes a little bit of extra work when inserting pays off greatly when reading.
You just have to be extra careful to sync correctly when inserting, as this issue shows. :wink:
This is probably one of the hardest things to implement correctly. Because we'll never be sure which Post type (CommentPost - default, EventPost - relabelling & locking for instance, PollPost or anything else) is valid to be included in this count without actually going over each entry in the relationship and checking the Type class implementation.
This should be an easy fix. Just change
$this->comment_count = $this->posts()->count();
to
$this->comment_count = $this->posts()->where('type', 'comment')->count();
What about is_private?
True, didn't think about that.
What if we had a UserMeta collection/class that would be extensible. In addition the default values, like comment_count and discussion_count are retrieved while dispatching an event. That logic could re-use the same logic used with the Policies perhaps..
I'm not too fond of more complexity, but it might be interesting to be able to create such statistical meta information on models.
Most helpful comment
This should be an easy fix. Just change
to