PERF: Store `EmailLog#bounce_key` as `uuid` data type. (#6093)

PERF: Store `EmailLog#bounce_key` as `uuid` data type.
This commit is contained in:
Guo Xiang Tan 2018-07-16 20:05:54 +08:00 committed by GitHub
parent f3868fd646
commit c0c263405a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -67,6 +67,10 @@ class EmailLog < ActiveRecord::Base
.try(:to_address) .try(:to_address)
end end
def bounce_key
super&.delete('-')
end
end end
# == Schema Information # == Schema Information

View File

@ -0,0 +1,9 @@
class AlterBounceKeyOnEmailLogs < ActiveRecord::Migration[5.2]
def up
change_column :email_logs, :bounce_key, 'uuid USING bounce_key::uuid'
end
def down
change_column :email_logs, :bounce_key, :string
end
end

View File

@ -101,4 +101,19 @@ describe EmailLog do
end end
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)
raw_bounce_key = EmailLog.where(id: email_log.id)
.pluck("bounce_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)
end
end
end end