From bdeb6ff18049870e76139f7434249096bc4d1fca Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 20 Mar 2023 20:02:58 +0100 Subject: [PATCH] Fix crash in `tootctl` commands making use of parallelization when Elasticsearch is enabled (#24182) --- lib/mastodon/cli_helper.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/mastodon/cli_helper.rb b/lib/mastodon/cli_helper.rb index 8704edd75e..ab1351ae80 100644 --- a/lib/mastodon/cli_helper.rb +++ b/lib/mastodon/cli_helper.rb @@ -52,14 +52,16 @@ module Mastodon progress.log("Processing #{item.id}") if options[:verbose] - result = ActiveRecord::Base.connection_pool.with_connection do - yield(item) - ensure - RedisConfiguration.pool.checkin if Thread.current[:redis] - Thread.current[:redis] = nil + Chewy.strategy(:mastodon) do + result = ActiveRecord::Base.connection_pool.with_connection do + yield(item) + ensure + RedisConfiguration.pool.checkin if Thread.current[:redis] + Thread.current[:redis] = nil + end + + aggregate.increment(result) if result.is_a?(Integer) end - - aggregate.increment(result) if result.is_a?(Integer) rescue => e progress.log pastel.red("Error processing #{item.id}: #{e}") ensure