Skip to content

Commit

Permalink
fix: use utc timestamps when determining raw table names
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Feb 1, 2024
1 parent 8794a2f commit ce19bf7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/postal/message_db/database.rb
Expand Up @@ -107,7 +107,7 @@ def raw_table_name_for_date(date)
#
# Insert a new raw message into a table (creating it if needed)
#
def insert_raw_message(data, date = Date.today)
def insert_raw_message(data, date = Time.now.utc.to_date)
table_name = raw_table_name_for_date(date)
begin
headers, body = data.split(/\r?\n\r?\n/, 2)
Expand Down
2 changes: 1 addition & 1 deletion lib/postal/message_db/message.rb
Expand Up @@ -263,7 +263,7 @@ def save_raw_message
return unless @pending_raw_message

self.size = @pending_raw_message.bytesize
date = Date.today
date = Time.now.utc.to_date
table_name, headers_id, body_id = @database.insert_raw_message(@pending_raw_message, date)
self.raw_table = table_name
self.raw_headers_id = headers_id
Expand Down
4 changes: 2 additions & 2 deletions lib/postal/message_db/provisioner.rb
Expand Up @@ -94,7 +94,7 @@ def create_raw_table(table)
# Return a list of raw message tables that are older than the given date
#
def raw_tables(max_age = 30)
earliest_date = max_age ? Date.today - max_age : nil
earliest_date = max_age ? Time.now.utc.to_date - max_age : nil
[].tap do |tables|
@database.query("SHOW TABLES FROM `#{@database.database_name}` LIKE 'raw-%'").each do |tbl|
tbl_name = tbl.to_a.first.last
Expand Down Expand Up @@ -128,7 +128,7 @@ def remove_raw_table(table)
# 聽Remove messages from the messages table that are too old to retain
#
def remove_messages(max_age = 60)
time = (Date.today - max_age.days).to_time.end_of_day
time = (Time.now.utc.to_date - max_age.days).to_time.end_of_day
return unless newest_message_to_remove = @database.select(:messages, where: { timestamp: { less_than_or_equal_to: time.to_f } }, limit: 1, order: :id, direction: "DESC", fields: [:id]).first

id = newest_message_to_remove["id"]
Expand Down

0 comments on commit ce19bf7

Please sign in to comment.