5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 11:46:22 +00:00

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 # 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, MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
:value, :help, :required, :errors, :post, :value, :help, :required, :errors, :post,
:layout, keyword_init: true) do :layout, keyword_init: true) do
@ -12,6 +11,22 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
attr_reader :value_was 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) def value=(new_value)
@value_was = value @value_was = value
self[:value] = new_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 @box ||= Lockbox.new key: site.private_key, padding: true, encode: true
end end
end end
# rubocop:enable Metrics/BlockLength

View file

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

View file

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