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

See https://github.com/discourse/discourse/pull/22854#discussion_r1277542736.
This commit is contained in:
Andrei Prigorshnev 2023-07-28 20:17:04 +04:00 committed by GitHub
parent 81cf481b16
commit 7c67360d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 5 deletions

View File

@ -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