Skip to content

A platform for community discussion. Free, open, simple.

DEV: a better way of picking of the earliest date (#22858)

Andrei Prigorshnev7c67360d4a6d
diff --git a/plugins/chat/lib/chat/messages_exporter.rb b/plugins/chat/lib/chat/messages_exporter.rb
index 2374bbed210..e2018099dde 100644
--- a/plugins/chat/lib/chat/messages_exporter.rb
+++ b/plugins/chat/lib/chat/messages_exporter.rb
@@ -5,7 +5,7 @@ module Chat
def chat_message_export(&block)
# perform 1 db query per month:
now = Time.now
- from = oldest_message_date
+ from = Chat::Message.minimum(:created_at)
while from <= now
export(from, from + 1.month, &block)
from = from + 1.month
@@ -36,10 +36,6 @@ module Chat
private
- def oldest_message_date
- Chat::Message.order(:created_at).pick(:created_at)
- end
-
def export(from, to)
Chat::Message
.unscoped