cachear metadatos #177

This commit is contained in:
f 2020-11-11 17:00:09 -03:00
parent a14ecee220
commit 59a6b94f5e
3 changed files with 36 additions and 18 deletions

View file

@ -4,7 +4,6 @@
#
# TODO: Validar el tipo de valor pasado a value= según el :type
#
# rubocop:disable Metrics/BlockLength
MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
:value, :help, :required, :errors, :post,
:layout, keyword_init: true) do
@ -12,6 +11,22 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
attr_reader :value_was
# Queremos que los artículos nuevos siempre cacheen, si usamos el UUID
# siempre vamos a obtener un item nuevo.
def cache_key
return name.to_s if post.new?
@cache_key ||= 'post/' + post.uuid.value + '/' + name.to_s
end
def cache_version
value.hash.to_s
end
def cache_key_with_version
cache_key + '-' + cache_version
end
def value=(new_value)
@value_was = value
self[:value] = new_value
@ -162,4 +177,3 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
@box ||= Lockbox.new key: site.private_key, padding: true, encode: true
end
end
# rubocop:enable Metrics/BlockLength

View file

@ -40,14 +40,15 @@
-# Dibuja cada atributo
- post.attributes.each do |attribute|
- metadata = post.send(attribute)
- metadata = post[attribute]
- type = metadata.type
= render("posts/attributes/#{type}",
post: post, attribute: attribute,
metadata: metadata, site: site,
dir: dir, locale: @locale,
autofocus: (post.attributes.first == attribute))
- cache metadata do
= render("posts/attributes/#{type}",
post: post, attribute: attribute,
metadata: metadata, site: site,
dir: dir, locale: @locale,
autofocus: (post.attributes.first == attribute))
-# Botones de guardado
= render 'posts/submit', site: site, post: post

View file

@ -26,17 +26,20 @@
- metadata = @post[attr]
- next unless metadata.front_matter?
= render("posts/attribute_ro/#{metadata.type}",
post: @post, attribute: attr,
metadata: metadata,
site: @site,
tags: all_html_tags,
locale: @locale,
dir: dir)
- cache metadata do
= render("posts/attribute_ro/#{metadata.type}",
post: @post, attribute: attr,
metadata: metadata,
site: @site,
tags: all_html_tags,
locale: @locale,
dir: dir)
-# Mostrar todo lo que no va en el front_matter (el contenido)
- @post.attributes.each do |attr|
- next if @post.send(attr).front_matter?
- metadata - @post[attr]
- next if metadata.front_matter?
%section{ id: attr, dir: dir }
= @post.send(attr).to_s.html_safe
- cache metadata do
%section{ id: attr, dir: dir }
= @post.public_send(attr).to_s.html_safe