Cache content cache key on a per-request basis
We do a similar thing with the settings helper, caching settings on a per-request basis. Using an instance variable in a helper reduces the amount of times we need to calculate the cache key during a single request. Even if Rails caches SQL queries per request, the test suite is faster with this change, and we get rid of many redundant queries in the logs.
This commit is contained in:
@@ -8,7 +8,11 @@ module ActionView
|
||||
|
||||
def t(key, options = {})
|
||||
current_locale = options[:locale].presence || I18n.locale
|
||||
translation = I18nContent.translations_hash(current_locale)[key]
|
||||
|
||||
@i18n_content_translations ||= {}
|
||||
@i18n_content_translations[current_locale] ||= I18nContent.translations_hash(current_locale)
|
||||
|
||||
translation = @i18n_content_translations[current_locale][key]
|
||||
|
||||
if translation.present?
|
||||
translation % options
|
||||
|
||||
Reference in New Issue
Block a user