From 731fcad3d536c45c639e6a4bb7160b29236f01f5 Mon Sep 17 00:00:00 2001 From: Osama Sayegh Date: Tue, 30 Jul 2024 13:54:17 +0300 Subject: [PATCH] FIX: Perform topics merge in a background thread (#28114) Similar to https://github.com/discourse/discourse/pull/28061, merging topics with many posts can exceed the 30 seconds timeout that Unicorn workers are limited to, so we should move the operation into a background thread to get around this limit. Internal topic: t/133710. --- app/controllers/topics_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index f6f99aa0b0f..95431ad9825 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -855,8 +855,11 @@ class TopicsController < ApplicationController params[:archetype] == "private_message" end - destination_topic = topic.move_posts(current_user, topic.posts.pluck(:id), args) - render_topic_changes(destination_topic) + acting_user = current_user + hijack(info: "merging topic #{topic_id.inspect} into #{destination_topic_id.inspect}") do + destination_topic = topic.move_posts(acting_user, topic.posts.pluck(:id), args) + render_topic_changes(destination_topic) + end end def move_posts