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:
parent
81cf481b16
commit
7c67360d4a
|
@ -5,7 +5,7 @@ module Chat
|
||||||
def chat_message_export(&block)
|
def chat_message_export(&block)
|
||||||
# perform 1 db query per month:
|
# perform 1 db query per month:
|
||||||
now = Time.now
|
now = Time.now
|
||||||
from = oldest_message_date
|
from = Chat::Message.minimum(:created_at)
|
||||||
while from <= now
|
while from <= now
|
||||||
export(from, from + 1.month, &block)
|
export(from, from + 1.month, &block)
|
||||||
from = from + 1.month
|
from = from + 1.month
|
||||||
|
@ -36,10 +36,6 @@ module Chat
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def oldest_message_date
|
|
||||||
Chat::Message.order(:created_at).pick(:created_at)
|
|
||||||
end
|
|
||||||
|
|
||||||
def export(from, to)
|
def export(from, to)
|
||||||
Chat::Message
|
Chat::Message
|
||||||
.unscoped
|
.unscoped
|
||||||
|
|
Loading…
Reference in New Issue