From c2f7da32985120238c54636b700baa2c1baf9849 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 17 Dec 2024 16:47:34 +1100 Subject: [PATCH] FIX: Restrict duplicate timings from being moved with posts (#30311) --- app/models/post_mover.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 17c116ae80d..1f69c8aa96a 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -478,7 +478,9 @@ class PostMover def copy_shifted_post_timings_from_temp DB.exec <<~SQL INSERT INTO post_timings (topic_id, user_id, post_number, msecs) - SELECT DISTINCT topic_id, user_id, post_number, msecs FROM temp_post_timings + SELECT DISTINCT ON (topic_id, post_number, user_id) topic_id, user_id, post_number, msecs + FROM temp_post_timings + ORDER BY topic_id, post_number, user_id, msecs DESC ON CONFLICT (topic_id, post_number, user_id) DO UPDATE SET msecs = GREATEST(post_timings.msecs, excluded.msecs) SQL