Discrepancies in webhook topic_posts_count

We use the Discourse web hook Post Event (When there is a new reply, edit, deleted or recovered). When a post in a topic (comment) is made, it sends a web hook and we use that information to update data on the WP side.

I notice that the web hook does not send accurate data, in the topic_filtered_posts_count or topic_posts_count, after some posts in a topic are deleted. It produces the correct counts as long as comments are added or edited. However as soon as a comment or more than one get deleted these counts start to be off by small values (but unreliably, sometimes off by one, sometimes off by two, etc).

We inspected the webhook payloads to see if the issue was on WP or Discourse side and it turns out that the webhooks are sending incorrect information. Sometimes there is even a discrepancy between topic_posts_count and topic_filtered_posts_count in situations where all posts are archetype :regular and there are no current deleted posts.

This leads me to believe the issue is caused by asynchronous handling of both the webhook and the (un)deletion but I’m not sure if that’s really the case.

2 Likes

I came across this when looking into this issue:

I’ve made a PR which fixes it:

4 Likes