Skip to content

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

PERF: Store `EmailLog#reply_key` as `uuid` data type.

Guo Xiang Tan3553375dd2be
diff --git a/app/models/email_log.rb b/app/models/email_log.rb
index b105371d893..ee57d0db19f 100644
--- a/app/models/email_log.rb
+++ b/app/models/email_log.rb
@@ -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)
diff --git a/db/migrate/20180717084758_alter_reply_key_on_email_logs.rb b/db/migrate/20180717084758_alter_reply_key_on_email_logs.rb
new file mode 100644
index 00000000000..0ace7e05670
--- /dev/null
+++ b/db/migrate/20180717084758_alter_reply_key_on_email_logs.rb
@@ -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
diff --git a/spec/models/email_log_spec.rb b/spec/models/email_log_spec.rb
index c51da8ed404..8608cc01a19 100644
--- a/spec/models/email_log_spec.rb
+++ b/spec/models/email_log_spec.rb
@@ -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)
-
- 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)
+ %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_key = EmailLog.where(id: email_log.id)
+ .pluck("#{key}::text")
+ .first
+
+ 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