PERF: Store `EmailLog#reply_key` as `uuid` data type.
This commit is contained in:
parent
22dad7f0e8
commit
3553375dd2
|
@ -71,6 +71,10 @@ class EmailLog < ActiveRecord::Base
|
|||
super&.delete('-')
|
||||
end
|
||||
|
||||
def reply_key
|
||||
super&.delete('-')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
@ -83,7 +87,7 @@ end
|
|||
# user_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# reply_key :string(32)
|
||||
# reply_key :uuid
|
||||
# post_id :integer
|
||||
# topic_id :integer
|
||||
# skipped :boolean default(FALSE)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class AlterReplyKeyOnEmailLogs < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
change_column :email_logs, :reply_key, 'uuid USING reply_key::uuid'
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :email_logs, :reply_key, :string
|
||||
end
|
||||
end
|
|
@ -101,19 +101,20 @@ describe EmailLog do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#bounce_key' do
|
||||
it 'should format the bounce key correctly' do
|
||||
bounce_key = SecureRandom.hex
|
||||
email_log = Fabricate(:email_log, user: user, bounce_key: bounce_key)
|
||||
%w{reply_key bounce_key}.each do |key|
|
||||
describe "##{key}" do
|
||||
it "should format the #{key} correctly" do
|
||||
hex = SecureRandom.hex
|
||||
email_log = Fabricate(:email_log, user: user, "#{key}": hex)
|
||||
|
||||
raw_bounce_key = EmailLog.where(id: email_log.id)
|
||||
.pluck("bounce_key::text")
|
||||
.first
|
||||
raw_key = EmailLog.where(id: email_log.id)
|
||||
.pluck("#{key}::text")
|
||||
.first
|
||||
|
||||
expect(raw_bounce_key).to_not eq(bounce_key)
|
||||
expect(raw_bounce_key.delete('-')).to eq(bounce_key)
|
||||
expect(EmailLog.find(email_log.id).bounce_key).to eq(bounce_key)
|
||||
expect(raw_key).to_not eq(hex)
|
||||
expect(raw_key.delete('-')).to eq(hex)
|
||||
expect(EmailLog.find(email_log.id).send(key)).to eq(hex)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue