FIX: N+1 query on topics view page.

This commit is contained in:
Guo Xiang Tan 2016-02-23 16:00:39 +08:00 committed by Robin Ward
parent 90e017ffef
commit 8dad58ba78

View file

@ -106,13 +106,19 @@ module I18n
by_site = @overrides_by_site[site]
unless by_site && by_site.has_key?(locale)
if by_site.nil? || !by_site.has_key?(locale)
by_site = @overrides_by_site[site] = {}
# Load overrides
TranslationOverride.where(locale: locale).pluck(:translation_key, :value).each do |tuple|
by_locale = by_site[locale] ||= {}
by_locale[tuple[0]] = tuple[1]
translations_overrides = TranslationOverride.where(locale: locale).pluck(:translation_key, :value)
if translations_overrides.empty?
by_site[locale] = {}
else
translations_overrides.each do |tuple|
by_locale = by_site[locale] ||= {}
by_locale[tuple[0]] = tuple[1]
end
end
end