Skip to content

A platform for community discussion. Free, open, simple.

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

Guo Xiang Tanc0c263405a72
diff --git a/app/models/email_log.rb b/app/models/email_log.rb
index d365ae01f47..8e764c43350 100644
--- a/app/models/email_log.rb
+++ b/app/models/email_log.rb
@@ -67,6 +67,10 @@ class EmailLog < ActiveRecord::Base
.try(:to_address)
end
+ def bounce_key
+ super&.delete('-')
+ end
+
end
# == Schema Information
diff --git a/db/migrate/20180716072125_alter_bounce_key_on_email_logs.rb b/db/migrate/20180716072125_alter_bounce_key_on_email_logs.rb
new file mode 100644
index 00000000000..e7c064eb8a0
--- /dev/null
+++ b/db/migrate/20180716072125_alter_bounce_key_on_email_logs.rb
@@ -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
diff --git a/spec/models/email_log_spec.rb b/spec/models/email_log_spec.rb
index a59c70f13fe..c51da8ed404 100644
--- a/spec/models/email_log_spec.rb
+++ b/spec/models/email_log_spec.rb
@@ -101,4 +101,19 @@ 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)
+
+ 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