| 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 hidden or 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 | |
| SOME_CONSTANT = "SOME_CONSTANT%{value}" | |
| puts SOME_CONSTANT % {value: "abcd.freshservice.com"} | |
| > "SOME_CONSTANT:abcd.freshservice.com" |
This file contains hidden or 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 | |
| SOME_CONSTANT = "SOME_CONSTANT" | |
| puts "#{SOME_CONSTANT}#{'abcd.freshservice.com'}" | |
| > "SOME_CONSTANT:abcd.freshservice.com" |
This file contains hidden or 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 Memcache | |
| KEY_HASH = YAML.load_file(File.join(Rails.root, 'config', 'memcached_keys.yml')).symbolize_keys! | |
| def self.key(key, value) | |
| “#{KEY_HASH[key]}:#{value}” | |
| end | |
| def self.multi_key(key, value1, value2) | |
| “#{KEY_HASH[key]}:#{value1}:#{value2}” | |
| end |
This file contains hidden or 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
| gem install memoize_until | |
| > irb | |
| irb:> require 'memoize_until' | |
| irb:> MemoizeUntil.hour(:default) { | |
| irb:> $redis.get("APP_CONFIGS") | |
| irb:> } | |
| irb:> # memoizes(until the end of the day) and returns the result of #PerformSomeComplexOperation |
This file contains hidden or 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
| gem 'memoize_until' |
This file contains hidden or 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 Middleware::CustomLogging | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) | |
| if debug_logging? | |
| Rails.logger.level = Logger::DEBUG | |
| end |
This file contains hidden or 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> |
This file contains hidden or 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 hidden or 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 | |
| ... |