# Different counting methods for Likes: user\_stats vs Badges \[maybe bug\]

**URL:** <https://meta.discourse.org/t/different-counting-methods-for-likes-user-stats-vs-badges-maybe-bug/58145>\
**Category:** UX\
**Created:** [1. März 2017 um 00:23 UTC](https://meta.discourse.org/t/different-counting-methods-for-likes-user-stats-vs-badges-maybe-bug/58145 "2017-03-01T00:23:07Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Lutz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lutz/32/65103_2.png) [@Lutz](https://meta.discourse.org/u/Lutz)\
**Post date:** [1. März 2017 um 00:23 UTC](https://meta.discourse.org/t/different-counting-methods-for-likes-user-stats-vs-badges-maybe-bug/58145/1 "2017-03-01T00:23:07Z")

</div>

We have a user who has over 1400 submitted Likes according to the User Summary. And also over 600 received Likes. Both for several days. He still has not received the Badge Emphatic (500 Likes received and 1000 given)

After some searching I found out that the Likes are counted differently here. In Summary the query is:

`
SELECT COUNT(*) FROM "user_actions" WHERE "user_actions"."user_id" = 15 AND "user_actions"."action_type" = 2 `  
"Likes Revived: " 638

```plaintext
SELECT COUNT(*) FROM "user_actions" WHERE "user_actions"."user_id" = 15 AND "user_actions"."action_type" = 1   
```

“Likes given”: 1471

For the badge is the condition as follows, so he should get the badge.

```plaintext
      SELECT us.user_id, current_timestamp AS granted_at
      FROM user_stats AS us
      INNER JOIN posts AS p ON p.user_id = us.user_id
      WHERE p.like_count> 0
        AND us.likes_given> = 1000
        AND (: backfill OR us.user_id IN (: user_ids))
      GROUP BY us.user_id, us.likes_given
      HAVING COUNT (*)> 500
```

The query

```plaintext
 SELECT us.user_id, count (*) cnt_likes_received, us.likes_given
      FROM user_stats AS us
      INNER JOIN posts AS p ON p.user_id = us.user_id
      WHERE p.like_count> 0
        AND us.user_id = 15
        AND us.likes_given >= 1000
      GROUP BY us.user_id, us.likes_given;
```

```
user_id cnt_likes_received likes_given
15 393 1462

```

This suggests that either user\_stats is completely wrong, or that the Likes are counted differently.  
I always get reports about this, because badges seem very important to our users.

Either “fix” user\_stats or change the query for the Badge.

Edit: I have no pending or broken sidekiq jobs. We use the latest test-passed branch from today.

---

_[View the full topic](https://meta.discourse.org/t/different-counting-methods-for-likes-user-stats-vs-badges-maybe-bug/58145)._
