A platform for community discussion. Free, open, simple.
DEV: Ignore Posts with out topics when reordering posts based on their creation date (#35122)
Juan David Martínez Cubillosb880921acfbc
diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rakeindex 5c8df012813..26afa83fc18 100644--- a/lib/tasks/posts.rake+++ b/lib/tasks/posts.rake@@ -388,16 +388,17 @@ task "posts:reorder_posts", [:topic_id] => [:environment] do |_, args|builder = DB.build <<~SQLWITH ordered_posts AS (SELECT- id,+ p.id,ROW_NUMBER() OVER (PARTITION BY- topic_id+ p.topic_idORDER BY- created_at,- post_number+ p.created_at,+ p.post_number) AS new_post_numberFROM- posts+ posts p+ INNER JOIN topics t ON t.id = p.topic_id/*where*/)UPDATE@@ -412,7 +413,7 @@ task "posts:reorder_posts", [:topic_id] => [:environment] do |_, args|p.post_number <> o.new_post_numberSQL- builder.where("topic_id = ?", args[:topic_id]) if args[:topic_id]+ builder.where("p.topic_id = ?", args[:topic_id]) if args[:topic_id]builder.exec[@@ -429,6 +430,7 @@ task "posts:reorder_posts", [:topic_id] => [:environment] do |_, args|#{column} = p.sort_order * -1FROMposts AS p+ INNER JOIN topics t ON t.id = p.topic_id/*where*/SQL@@ -450,14 +452,17 @@ task "posts:reorder_posts", [:topic_id] => [:environment] do |_, args|builder = DB.build <<~SQLUPDATE- posts+ posts AS pSETpost_number = sort_order+ FROM+ topics t/*where*/SQL- builder.where("topic_id = ?", args[:topic_id]) if args[:topic_id]- builder.where("post_number < 0")+ builder.where("t.id = p.topic_id")+ builder.where("p.topic_id = ?", args[:topic_id]) if args[:topic_id]+ builder.where("p.post_number < 0")builder.execend