# User Summary - Most Liked By user attributions are incorrect

**URL:** https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668
**Category:** Bug
**Created:** [April 16, 2016, 8:07pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668 "2016-04-16T20:07:30Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Yuun](https://avatars.discourse-cdn.com/v4/letter/y/977dab/32.png) [@Yuun](https://meta.discourse.org/u/Yuun)
#### Post date: [April 16, 2016, 8:07pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/1 "2016-04-16T20:07:30Z")

</div>

**Issue:**

At for example [meta.discourse.org/my/summary](https://meta.discourse.org/my/summary), the “Most Liked By” column containers the correct numbers of likes and the correct users, but does not match them up correctly.

This is a little easier to see when you’re the admin for the site and can check against a [data explorer](https://meta.discourse.org/t/32566?silent=true) query, though. I can’t easily verify it’s happened on meta, have seen the issue most clearly on my site.

**Repro:**

Nothing special required, just visit a user summary page and check the numbers against some other source. For example using the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin, or using the user directory in some circumstances (one of the “most liked by” for my page on my site, for example, is shown giving me more likes than he has given total on the user directory).

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [April 16, 2016, 9:00pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/2 "2016-04-16T21:00:14Z")

</div>

> [@Yuun](#):
>
> one of the “most liked by” for my page on my site, for example, is shown giving me more likes than he has given total on the user directory)

Are you sure you are looking at all time interval in the user list?

---

<div class="post-metadata">

### Author: ![Yuun](https://avatars.discourse-cdn.com/v4/letter/y/977dab/32.png) [@Yuun](https://meta.discourse.org/u/Yuun)
#### Post date: [April 16, 2016, 9:03pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/3 "2016-04-16T21:03:33Z")

</div>

Yup.

For reference, I’m using the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query detailed here as my main comparison: [Discourse Data Explorer](https://meta.discourse.org/t/data-explorer-plugin/32566).

The query and the summary both pull the same numbers and users, but they don’t match up correctly on the summary page.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [April 16, 2016, 9:05pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/4 "2016-04-16T21:05:06Z")

</div>

Sure @zogstrip there were some reports of weirdness with these numbers on BBS as well so this warrants a further look next week.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [April 16, 2016, 9:43pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/5 "2016-04-16T21:43:05Z")

</div>

> [@Yuun](#):
>
> I’m using the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query detailed here as my main comparison

AFAICT that query doesn’t take into consideration Likes that were given, then taken back (or otherwise negated).  
If you run

```sql
SELECT *
FROM post_actions
WHERE post_action_type_id = 2
AND user_id = deleted_by_id

```

does the difference in the count jive?

---

<div class="post-metadata">

### Author: ![Yuun](https://avatars.discourse-cdn.com/v4/letter/y/977dab/32.png) [@Yuun](https://meta.discourse.org/u/Yuun)
#### Post date: [April 16, 2016, 10:31pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/6 "2016-04-16T22:31:25Z")

</div>

Does it really? That’s kind of odd. Your suggested query doesn’t really give me an easy way to evaluate the difference, although maybe I’m not using it as you intended.

In any case though, thanks for looking into it, but I think it’s really unlikely that’s the issue. The set of counts and users between the query and the summary page are literally identical (and occupy a fairly wide range, they don’t differ by one or two likes), the counts are just attributed to different users on the summary page. The counts on the summary page don’t align well with my experience on the forum, either.

---

<div class="post-metadata">

### Author: ![purldator](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@purldator](https://meta.discourse.org/u/purldator)
#### Post date: [April 16, 2016, 11:26pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/7 "2016-04-16T23:26:26Z")

</div>

This occurs on FeverBee community forums.

[My summary](https://experts.feverbee.com/users/purldator/summary) says alenarybik gave me `21` ❤ but she has only given a total of `11 ` ❤ **to all** [as it says on her summary page](https://experts.feverbee.com/users/alenarybik/summary).

@HAWK should be there instead; switch places with alenarybik.

---

<div class="post-metadata">

### Author: ![HAWK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hawk/32/86627_2.png) [@HAWK](https://meta.discourse.org/u/HAWK)
#### Post date: [April 16, 2016, 11:29pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/8 "2016-04-16T23:29:18Z")

</div>

> [@purldator](#):
>
> as it says on her summary page

How strange. I’d never noticed that before!

---

<div class="post-metadata">

### Author: ![purldator](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@purldator](https://meta.discourse.org/u/purldator)
#### Post date: [April 16, 2016, 11:32pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/9 "2016-04-16T23:32:56Z")

</div>

Just noticed it yesterday and assumed it was a reported bug. Aye, it be. `*grin*`

Addendum: **It also incorrectly attributes @erlend_sh and @ccdw**. Erlend only ❤ `1` post of mine, that I can recall. Chris has ❤ `9` of my posts.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [April 17, 2016, 12:10am UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/10 "2016-04-17T00:10:00Z")

</div>

We definitely need to fix this @zogstrip

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 17, 2016, 12:26am UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/11 "2016-04-17T00:26:21Z")

</div>

Probably not excluding deleted votes or posts

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [April 17, 2016, 2:28am UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/12 "2016-04-17T02:28:33Z")

</div>

I’ve been playing with this in [Data Explorer](https://meta.discourse.org/t/32566?silent=true) (please forgive readability issues)

```sql
WITH tl AS ( SELECT SUM(topics.like_count) AS topics_like_sum
FROM topics )
, pl AS ( SELECT SUM(posts.like_count) AS posts_like_sum
FROM posts )
, pal AS ( SELECT COUNT(post_actions.id) AS pa_like_count 
FROM post_actions 
WHERE post_actions.post_action_type_id = 2 )
, padl AS ( SELECT COUNT(post_actions.id) AS deleted_pa_like_count 
FROM post_actions 
WHERE post_actions.post_action_type_id = 2
AND post_actions.deleted_at IS NOT NULL )
, bpl AS ( SELECT SUM(badge_posts.like_count) AS bp_like_sum
FROM badge_posts )
, pcl AS ( SELECT SUM(topics.like_count) AS priv_topic_like_sum 
FROM topics 
JOIN categories 
ON topics.category_id = categories.id 
WHERE categories.read_restricted )
SELECT
  tl.topics_like_sum
  , pl.posts_like_sum
  , pal.pa_like_count
  , padl.deleted_pa_like_count
  , bpl.bp_like_sum
  , pcl.priv_topic_like_sum
FROM 
  tl
  , pl 
  , pal
  , padl
  , bpl
  , pcl

```

For my test site I get

```
topics_like_sum 508
posts_like_sum 506
pa_like_count 513
deleted_pa_like_count 7
bp_like_sum 470
priv_topic_like_sum 32

```

513 - 7 = 506 which looks good.  
and 470 + 32 + 7 is close  
But I’m not seeing how Topic Likes and Posts Likes would differ.  
\* could be because I run rails s and sidekiq separately

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [April 17, 2016, 10:22am UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/13 "2016-04-17T10:22:59Z")

</div>

Thanks for reporting this issue @Yuun.  
Thanks @purldator for providing more evidences.  
Thanks @Mittineague for investigating.

Here’s a fix 😘

[https://github.com/discourse/discourse/commit/ae4dd6e679d60b0455df629be3bcb4eb0d10eb37](https://github.com/discourse/discourse/commit/ae4dd6e679d60b0455df629be3bcb4eb0d10eb37)

---

<div class="post-metadata">

### Author: ![Yuun](https://avatars.discourse-cdn.com/v4/letter/y/977dab/32.png) [@Yuun](https://meta.discourse.org/u/Yuun)
#### Post date: [April 17, 2016, 1:18pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/14 "2016-04-17T13:18:21Z")

</div>

Thanks for looking into it @zogstrip!

The numbers are slightly different now, looks like they are taking into account deleted/negated likes correctly, but the count-user matches are still incorrect on my site. This shouldn’t require a rebuild or a sidekiq job I need to wait for, right?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [April 17, 2016, 6:02pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/15 "2016-04-17T18:02:01Z")

</div>

As an off-topic follow-up

> [@Mittineague](#):
>
> But I’m not seeing how Topic Likes and Posts Likes would differ.

The difference has to do with 2 “parent” categories that do not have any Create Read Reply permissions but are used only to hold sub-categories.

That pesky LikerGuy1 Liked the “About the” posts for those no-replies “topics”.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [April 18, 2016, 7:18am UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/16 "2016-04-18T07:18:43Z")

</div>

> [@Yuun](#):
>
> but the count-user matches are still incorrect on my site.

Would you mind telling me more?

---

<div class="post-metadata">

### Author: ![Yuun](https://avatars.discourse-cdn.com/v4/letter/y/977dab/32.png) [@Yuun](https://meta.discourse.org/u/Yuun)
#### Post date: [April 18, 2016, 11:23am UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/17 "2016-04-18T11:23:24Z")

</div>

Not at all, let me use my summary here as an example:

 ![](https://global.discourse-cdn.com/meta/original/3X/2/a/2ada752dcd9a4bb48a936f316d831a555b38b2e9.png)

This says my posts are most liked by sam at 45, with yourself at 14. This doesn’t really match with my experience here, where you are a much more prolific user of the like button. 😉

To check, if I go to my Likes Received notification page, by hand I count:

zogstrip: 45 likes  
sam: 14 likes

On my site, the summary page says a user has liked my posts 211 likes, whereas according to the user directory and that user’s own summary page, they’ve only given 136 likes total.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [April 18, 2016, 11:24am UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/18 "2016-04-18T11:24:13Z")

</div>

Hmm so maybe the names are wrong? Somehow Sam is appearing where Regis should? Thanks for your persistence with helping us in this @yuun.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [April 18, 2016, 12:50pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/19 "2016-04-18T12:50:56Z")

</div>

Thanks 👍 I know what’s happening. ~~Will fix.~~ It’s now fixed 😉

[https://github.com/discourse/discourse/commit/270ab5b71de2ead3cf6506cf9d25e38f0a32d3ec](https://github.com/discourse/discourse/commit/270ab5b71de2ead3cf6506cf9d25e38f0a32d3ec)

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [April 18, 2016, 9:47pm UTC](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668/20 "2016-04-18T21:47:26Z")

</div>

> [@Mittineague](#):
>
> The difference has to do with 2 “parent” categories that do not have any Create Read Reply permissions but are used only to hold sub-categories.
> 
> That pesky LikerGuy1 Liked the “About the” posts for those no-replies “topics”.

A correction is in order (as embarrassing as it s after Likes)  
It _should_ teach me to more thoroughly test _before_ posting results.

Anyway, I decided to repro and had LikerGal1 Like the same parent Cat OPs .  
No repro, ☹

Being a comparatively small localhost forum a lot of numbers have not diverged greatly and I looked for other “two occurrences events” that might be involved.

LikerGuy1 had also Liked 2 “hidden by Flags” posts.  
LikerGal1 did similar, - No repro, ☹

LikerGuy1 had also Liked 2 posts made by anonymous-mode members that were subsequently deleted by a Mod  
LikerGal1 did the same - repro !!

Was it because the posts had been made in anonymous-mode?  
A friendly member made a test post. Another Liked it, then it was Mod deleted. - repro !!

So unfortunately this isn’t as edge case as a topic-less category getting a Like.  
It seems that Liking any post that is subsequently deleted will decrement the post like count, but _will not decrement_ the associated topics like count.

Still a bit edge case I suppose, but maybe worth looking into if topic like count is used in value weighting algorithms.

[Next page](https://meta.discourse.org/t/user-summary-most-liked-by-user-attributions-are-incorrect/42668.md?page=2)
