Benchmarks | User | System | Total | Real |
---|---|---|---|---|
Rehearsal | ||||
Existing | 2.600000 | 0.240000 | 2.840000 | (2.833792) |
New | 1.190000 | 0.010000 | 1.200000 | (1.206466) |
Actual | ||||
Existing | 2.140000 | 0.050000 | 2.190000 | (2.194628) |
New | 0.830000 | 0.010000 | 0.840000 | (0.835711) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationMailer < ActionMailer::Base | |
before_action :block_spam_accounts, if: -> { Tenant.current.spam? } | |
private | |
def block_spam_accounts | |
self.response_body= "Abort!" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationMailer < ActionMailer::Base | |
before_action :block_spam_accounts, if: -> { Tenant.current.spam? } | |
private | |
def block_spam_accounts | |
message.perform_deliveries = false | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MailboxInterceptor | |
def self.delivering_email(mail) | |
set_smtp_settings(mail) | |
fix_encodings | |
mail.perform_deliveries = Rails.env.production? || File.exists?("#{Rails.root}/tmp/send_emails.txt") | |
ensure | |
unset_email_config | |
end | |
end | |
ActionMailer::Base.register_interceptor(MailboxInterceptor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MailObserver | |
def self.delivered_email(mail) | |
logger = ActionMailer::Base.logger | |
logger.tagged(mail.message_id) do | |
logger.info do | |
recipients = Array(mail.to).join(', ') | |
"Sent mail to #{recipients}" | |
end | |
end | |
logger.debug { mail.encoded } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MailboxInterceptor | |
def self.delivering_email(mail) | |
set_smtp_settings(mail) | |
fix_encodings | |
ensure | |
unset_email_config | |
end | |
private | |
def self.set_smtp_settings(mail) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Before | |
class User < ActiveRecord::Base | |
validates_uniqueness_of :username, message: :taken | |
end | |
# After | |
class User < ActiveRecord::Base | |
handle_record_not_unique(field: ["username"], message: {username: :taken}) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tenant < ActiveRecord::Base | |
... | |
# associations | |
has_one :tenant_configs | |
delegate :locale, :timezone, :date_format, ..., to: :tenant_configs_from_cache | |
def tenant_configs_from_cache | |
Rails.cache.fetch(“tenant_configs:#{self.id}:#{self.tenant_configs.updated_at.to_i}”) { self.tenant_configs } | |
end | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tenant < ActiveRecord::Base | |
... | |
# associations | |
has_one :tenant_configs | |
delegate :locale, :timezone, :date_format, ..., to: :tenant_configs | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):024:0> MemoizeUntil.const_get(:TYPE_FACTORY)[:day] | |
=> #<MemoizeUntil::Store:0x00007f8a61415be8 @_store={:flags_from_redis=>{18=>1}, :default=>{}}, @_kind=:day> | |
irb(main):025:0> MemoizeUntil.day(:default) { nil } | |
=> nil | |
irb(main):026:0> MemoizeUntil.const_get(:TYPE_FACTORY)[:day] | |
=> #<MemoizeUntil::Store:0x00007f8a61415be8 @_store={:flags_from_redis=>{18=>1}, :default=>{18=>#<MemoizeUntil::NullObject:0x00007f8a640226c8>}}, @_kind=:day> |
NewerOlder