# When merging posts, likes of the posts being merged do not add up to the final post

**URL:** https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918
**Category:** Bug
**Created:** [August 20, 2016, 10:55am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918 "2016-08-20T10:55:38Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [August 20, 2016, 10:55am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/1 "2016-08-20T10:55:38Z")

</div>

Not sure if this can be considered a bug.

When merging 3 posts with 4, 3 and 2 likes respectively in this exact order, the final post gets only 2 likes. I expect to see 4 likes, if not more (should be DISTINCT likes of all posts).

Example who liked posts:

Post 1: A, B, C, D (4 likes)  
Post 2: A, B, E (3 likes)  
Post 3: C, D (2 likes)

Resulting likes should be: A, B, C, D, E (5 likes)

P.S. A, B, C, D and E are nicknames who liked the posts.

---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [August 20, 2016, 2:51pm UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/2 "2016-08-20T14:51:12Z")

</div>

Duplicate of this:

> [@Transfer likes when moving a new topic into an existing one](https://meta.discourse.org/t/transfer-likes-when-moving-a-new-topic-into-an-existing-one/44234):
>
> I just noticed that when moving a topic (not a reply) into another topic that already existed, the moved topic will lose its likes. Here’s an actual example of a [topic](https://meta.discourse.org/t/upgrade-everything-at-once/44126) that was [merged into an existing one](https://meta.discourse.org/t/discourse-docker-manager-upgrade-all/33808/6). This happens because when we merge a topic into another one, we don’t actually move that topic, instead we close it and make a duplicate of it in the other topic. This inadvertently strips the topic of its likes. Could we: migrate the likes from the “moved” topic to the new post, and remov…

I do agree that this verges on #Contribute > Bug territory, since we’re basically causing loss of data.

---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [August 20, 2016, 2:51pm UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/3 "2016-08-20T14:51:15Z")

</div>



---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [October 29, 2018, 9:02am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/4 "2018-10-29T09:02:10Z")

</div>



---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [October 29, 2018, 12:22pm UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/5 "2018-10-29T12:22:21Z")

</div>

H there! Just wanted to say that this bug is not actually a duplicate and it still exists. Just merged posts couple days ago on up-to-date Dicourse and the likes were not transferred.

Thanks @erlend_sh for reopening this.

---

<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: [October 29, 2018, 3:21pm UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/6 "2018-10-29T15:21:17Z")

</div>

Wait are you referring to the actual “merge posts” function?

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [October 29, 2018, 3:48pm UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/7 "2018-10-29T15:48:27Z")

</div>

Yes, I first selected the posts and then merged them.

---

<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: [October 30, 2018, 12:01am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/8 "2018-10-30T00:01:08Z")

</div>

Yeah this is basically a bug. Could be a starter task though cc @erlend_sh.

---

<div class="post-metadata">

### Author: ![saurabhp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saurabhp/32/125182_2.png) [@saurabhp](https://meta.discourse.org/u/saurabhp)
#### Post date: [November 23, 2018, 9:05am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/9 "2018-11-23T09:05:30Z")

</div>

Hi @codinghorror,  
I was looking through this bug. I found out when we do merge\_posts, we pseudo\_delete all posts except one which becomes the merged post.

So for all the posts except merged\_post, we delete their user\_actions for `was_liked`. So to transfer likes, I will have to get all the `was_liked` actions for deleted\_posts. Out of those likes, users which haven’t liked the merged\_post, we can create `user_action` for them corresponding to merged\_post.

What do you think about this approach?

Also, there is an option to recover post. When that happens, all `was_liked` actions are re-created too using `post_action`. In that case, the merged post will have new likes equal to likes to all the merged posts and recovered\_post will also get back its likes thus increasing number of likes.

Thanks

---

<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: [November 26, 2018, 12:12am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/10 "2018-11-26T00:12:44Z")

</div>

Oh my… this is not really an ideal started task, its actually quite fiddly and tricky as you discovered @saurabhp

I think the most correct thing to stop with this unconditional deleting of user actions and deal with elimination of duplication instead. The extra tricky thing is you need to deal with post\_actions and user\_actions here. Also once you do all this stuff you have to float the correct number up to the topic.

Recovery here is a nighmare, once we allow this then this turns into hell basically to implement cause we need to yank out the likes on recovery.

I kind of want to put dealing with this on the back burner.

---

<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: [November 26, 2018, 12:53am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/11 "2018-11-26T00:53:12Z")

</div>

Er what? It’s literally adding numbers together. Perhaps you misunderstood the request? We are not talking about merging _topics_ we are talking about merging _posts_.

> [@meglio](#):
>
> When merging 3 posts with 4, 3 and 2 likes respectively in this exact order, the final post gets only 2 likes

Right now merged posts effectively have their likes _removed_. That’s clearly wrong.

---

<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: [November 26, 2018, 1:04am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/12 "2018-11-26T01:04:07Z")

</div>

Let me explain the technical problem here:

1. Sam posts reply 1
2. Sam posts reply 2
3. Jane + Fred likes reply 1
4. Jane + Jess likes reply 2

Admin merges reply 1 and reply 2

### Current behavior

- Reply 1 is deleted
- Reply 2 is liked by Jane + Jess
- Reply 2 is NOT liked by Fred, which admin was expecting, thus a like is missing in action.

### Proposal

Move Freds like on reply 1 to reply 2

### Problem

If you undelete Freds post and try to undo the “merge”, Janes like AND Freds like on “reply 1” will be gone.

### Possible mitigation

Create dupe like on reply 2, also messy.

* * *

I just find that the cure here is worse than the disease.

---

<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: [November 26, 2018, 1:04am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/13 "2018-11-26T01:04:58Z")

</div>

I see. So the duplicate likes by the same person are a problem. That makes sense, as we are consolidating all likes on {x} posts to 1 post.

Do we currently merge all NON duplicate likes when post merging, at least?

---

<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: [November 26, 2018, 1:06am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/14 "2018-11-26T01:06:48Z")

</div>

No we do not do any merging or consolidating, if we do any of that we effectively are allowing mods to perform an action they can not undo. Currently undo is very simple, delete a block of text, undo delete of other post.

---

<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: [November 26, 2018, 1:08am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/15 "2018-11-26T01:08:45Z")

</div>

I don’t think that’s a big deal, who is asking to undo a post merge? I’m saying, completely ignore dupe likes, and combine all the non-dupe likes.

It does make sense that the numbers will not add up, due to duplicate likes, e.g. if Sally likes all 3 posts, 2 of them are discarded because she liked the final merged post anyway.

---

<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: [November 26, 2018, 1:51am UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/16 "2018-11-26T01:51:44Z")

</div>

@saurabhp OK looks like you have your answer:

On merge

1. Take all the post and user actions that are “like / was liked” and transfer them to the new merged post, taking care of making it a NO-OP for dupes

2. Don’t worry at all about the recover scenario, if you try to unmerge, some likes will end up on the wrong post by design.

---

<div class="post-metadata">

### Author: ![danekhollas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danekhollas/32/79637_2.png) [@danekhollas](https://meta.discourse.org/u/danekhollas)
#### Post date: [November 26, 2018, 10:01pm UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/17 "2018-11-26T22:01:53Z")

</div>

I’d say that potentially spreading more ❤ is definitely better than the opposite. 🙂

Thanks @saurabhp for working on this and good luck! 💪

---

<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: [November 26, 2018, 10:19pm UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/18 "2018-11-26T22:19:13Z")

</div>

Also it allow to teleport likes between posts by moderators 🤪

I just realised one more table needs touching, notifications for likes may point to the wrong posts, so that also needs fixing. So we have 3 tables at play, `notifications`, `user_actions` and `post_actions` .

---

<div class="post-metadata">

### Author: ![saurabhp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saurabhp/32/125182_2.png) [@saurabhp](https://meta.discourse.org/u/saurabhp)
#### Post date: [November 28, 2018, 5:12pm UTC](https://meta.discourse.org/t/when-merging-posts-likes-of-the-posts-being-merged-do-not-add-up-to-the-final-post/48918/19 "2018-11-28T17:12:00Z")

</div>

Hi,

Can someone review my PR for the same.

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

Thanks
