Skip to content

[2.x] fix(likes): order likers with the same like time by user id - #5403

Open
karl-bullock wants to merge 1 commit into
flarum:2.xfrom
karl-bullock:fix/likes-stable-order
Open

karl-bullock wants to merge 1 commit into
flarum:2.xfrom
karl-bullock:fix/likes-stable-order

Conversation

@karl-bullock

Copy link
Copy Markdown
Member

Likes are stored to the second, so likers who liked in the same second came back in whatever order the database returned them. That decides which four likers a post lists, so the response could change between requests or database servers.

This adds user_id as a final tie-breaker after the actor-first and created_at ordering, as suggested in the issue.

Fixes #5244

The new test gives one post ten likes with an identical created_at, inserted out of id order. It checks that a non-liker gets the likers in user id order and the same on a second request, and that a liker still sees themselves first. On SQLite the primary key index already returns ties in id order, so the test passes there with or without the change; it pins the behavior for other drivers.

@karl-bullock
karl-bullock requested a review from a team as a code owner November 4, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Likers shown on a post have no stable order when they liked at the same time

1 participant