Discrepancies in webhook topic_posts_count

AI-generated summary

There is an inconsistency in the topic_posts_count and topic_filtered_posts_count fields of the Discourse webhook Post Event when posts are deleted from a topic. RGJ reports that the counts are accurate when posts are added or edited, but become unreliable after deletion, sometimes being off by one or multiple posts. The issue is suspected to be caused by asynchronous handling of webhook and post deletion. angus has found a related thread (meta.discourse.org) and created a pull request to resolve the issue.

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:

https://github.com/discourse/discourse/pull/29853

4 Likes