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

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.

2 Likes

Duplicate of this:

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

5 Likes

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.

1 Like

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

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

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

2 Likes

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

4 Likes

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.

2 Likes

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.

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

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.

1 Like

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?

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.

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.

3 Likes

@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.

5 Likes

I’d say that potentially spreading more :heart: is definitely better than the opposite. :slight_smile:

Thanks @saurabhp for working on this and good luck! :muscle:

5 Likes

Also it allow to teleport likes between posts by moderators :crazy_face:

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 .

4 Likes

Hi,

Can someone review my PR for the same.

https://github.com/discourse/discourse/pull/6678

Thanks

1 Like