From cd45f334302bf1ae666ab6e4254d4b19f2dc41ce Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Fri, 28 Jul 2023 17:04:57 +0400 Subject: [PATCH] FEATURE: Remove restrictions from the chat messages export (#22854) Now, when we took care of performance in fbe0e4c and ad05924 there is no need anymore to restrict the export to - 6 months - 10000 rows --- plugins/chat/lib/chat/messages_exporter.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/chat/lib/chat/messages_exporter.rb b/plugins/chat/lib/chat/messages_exporter.rb index b627049f9ef..2374bbed210 100644 --- a/plugins/chat/lib/chat/messages_exporter.rb +++ b/plugins/chat/lib/chat/messages_exporter.rb @@ -2,12 +2,10 @@ module Chat module MessagesExporter - LIMIT = 10_000 - def chat_message_export(&block) # perform 1 db query per month: now = Time.now - from = 6.months.ago + from = oldest_message_date while from <= now export(from, from + 1.month, &block) from = from + 1.month @@ -38,6 +36,10 @@ module Chat private + def oldest_message_date + Chat::Message.order(:created_at).pick(:created_at) + end + def export(from, to) Chat::Message .unscoped @@ -45,7 +47,6 @@ module Chat .includes(:chat_channel) .includes(:user) .includes(:last_editor) - .limit(LIMIT) .find_each do |chat_message| yield( [