edit_post action on wp_update_comment_count_now should not be fired if the comment count hasn't changed
|Reported by:||solarissmoke||Owned by:|
wp_update_comment_count_now() is called whenever a comment status is transitioned (or a comment is deleted). However, if the comment transition is not from/to the 'approved' status (e.g., if the comment is transitioned from 'spam' to 'trash' or from 'unapproved' to 'trash'), then the associated post is not actually affected. Therefore in such cases the edit_post action shouldn't be fired, because the post has not been edited/modified in any way. I would argue that the 'wp_update_comment_count' action also should not be fired.
One solution is to check whether the comment count has changed before firing the action. Another possible option is to call wp_update_comment_count only when a comment has transitioned in/out of the "approved" status. I'm inclined to prefer the former because it involves less change.
Proposed patch to follow.