# Discrepancies in webhook topic\_posts\_count

**URL:** https://meta.discourse.org/t/discrepancies-in-webhook-topic-posts-count/292741
**Category:** Bug
**Created:** [January 24, 2024, 9:02am UTC](https://meta.discourse.org/t/discrepancies-in-webhook-topic-posts-count/292741 "2024-01-24T09:02:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [January 24, 2024, 9:02am UTC](https://meta.discourse.org/t/discrepancies-in-webhook-topic-posts-count/292741/1 "2024-01-24T09:02:22Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [November 20, 2024, 4:27pm UTC](https://meta.discourse.org/t/discrepancies-in-webhook-topic-posts-count/292741/2 "2024-11-20T16:27:06Z")

</div>

I came across this when looking into this issue:

> [@Should comments webhook update count after deleting posts/comments?](https://meta.discourse.org/t/should-comments-webhook-update-count-after-deleting-posts-comments/336621):
>
> I’m using DC SSO where users are managed by WP. The forum acts as a way to comment on posts, but these posts are only visible in the forum. I have a custom “Comment” button in WP that turns into “x comments” when there are coments in the linked topic. (It uses normal WP get\_comments\_number that the DC plugin hooks into.) It works well, but I’ve just tried deleting a post and the count remains the same. The UI in the WP plugin recommends: Events: "Post is created", "Post is updated". Based on…

I’ve made a PR which fixes it:

[https://github.com/discourse/discourse/pull/29853](https://github.com/discourse/discourse/pull/29853)
