User post_count is zero in webhook for a user that has posts

We have a webhook on the event “user_logged_in”. The Payload contains the property post_count for the user that just logged in. Although the user did write 2 posts, the payload reads post_count: 0. This looks like a bug to me.

The receiver of the webhook needs this user stat to decide how to proceed.

The only similar topic I found is this one, might be related but does not talk about the same API: Category post_count not incrementing

1 Like

I have to correct myself: The post_count is not always zero. When checking with my own user, the post_count was plausible (though I don’t know whether it is accurate or not).

But there is a user on our site, let’s call it user #1234, for which the following holds:

  • SELECT * FROM posts WHERE user_id=1234 returns two entries in the table. These are the posts that are also listed in the user’s profile activity page
  • The webhook payload, when this user logs in or out, contains "post_count": 0.
1 Like

Hi @dpb,

I tested, and the post count isn’t updated in real-time.

My guess is that there’s a Sidekiq job that takes care of that periodically, but I don’t know which one.
It doesn’t seem there’s a specific related Sidekiq job :thinking:
But I read that this stat is updated at least once a day.

A GET request to https://your-discourse.org/u/username.json will return the right number, though.

If you want a reliable number, make such a request after receiving the webhook payload.

1 Like

Thanks @Canapin for suggesting the GET request to the API.

Well, in our case, the posts have been there for well over a month by now.

Maybe the component that updates this number stopped working at some arbitrary time during one of the updates?

Tested it, does not work either. Contains the same information: post_count: 0

Maybe there is a confusion with “topics” and “posts”. I expected that creating a new topic is just a special type of post. The database structure supports that.
But when checking the user profile statistics, they say something along the lines “2 topics created, 0 posts created”.
So maybe the “post_count” that I get is rather the number of replies to topics than the number of all posts?
On the other hand, there is a date “last_posted_at” which contains the date when the last topic was created. So at least, there is some inconsistency in naming here. I would expect the number “post_count” to include first posts in new topics, as well.

Anyway, whether this is intended behavior or not, I do not find a topic_count or alike in the user json. How do I find out the total number of posts, including new topics?

My json knowledge is a little fledgling but I can see the topic_count in https://meta.discourse.org/u/dpb/summary.json

1 Like