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:
Javi Martín
2020-12-13 14:33:35 +01:00
parent 41dba842a6
commit e38c1d637b

View File

@@ -8,7 +8,11 @@ module ActionView
def t(key, options = {}) def t(key, options = {})
current_locale = options[:locale].presence || I18n.locale 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? if translation.present?
translation % options translation % options