From 90a92ec25d75869c337deac061e67f8a39c13045 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 16 Nov 2020 19:17:40 -0300 Subject: [PATCH] =?UTF-8?q?aplicar=20la=20cach=C3=A9=20a=20los=20valores?= =?UTF-8?q?=20de=20referencia=20tambi=C3=A9n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/metadata_template.rb | 2 +- app/models/site.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/metadata_template.rb b/app/models/metadata_template.rb index 0e2e9c70..c59fb00a 100644 --- a/app/models/metadata_template.rb +++ b/app/models/metadata_template.rb @@ -20,7 +20,7 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type, end def cache_version - value.hash.to_s + value.hash.to_s + values.hash.to_s end def cache_key_with_version diff --git a/app/models/site.rb b/app/models/site.rb index 0e8db8cb..b053a6fc 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -291,11 +291,13 @@ class Site < ApplicationRecord # @param attr [Symbol|String] El atributo a buscar # @return Array def everything_of(attr, lang: nil) - attr = attr.to_sym + Rails.cache.fetch("#{cache_key_with_version}/everything_of/#{lang}/#{attr}", expires_in: 1.hour) do + attr = attr.to_sym - posts(lang: lang).flat_map do |p| - p[attr].value if p.attribute? attr - end.uniq.compact + posts(lang: lang).flat_map do |p| + p[attr].value if p.attribute? attr + end.uniq.compact + end end # Poner en la cola de compilaciĆ³n