5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 02:31:42 +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,9 +40,10 @@
-# 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
- cache metadata do
= render("posts/attributes/#{type}", = render("posts/attributes/#{type}",
post: post, attribute: attribute, post: post, attribute: attribute,
metadata: metadata, site: site, metadata: metadata, site: site,

View file

@ -26,6 +26,7 @@
- metadata = @post[attr] - metadata = @post[attr]
- next unless metadata.front_matter? - next unless metadata.front_matter?
- cache metadata do
= render("posts/attribute_ro/#{metadata.type}", = render("posts/attribute_ro/#{metadata.type}",
post: @post, attribute: attr, post: @post, attribute: attr,
metadata: metadata, metadata: metadata,
@ -36,7 +37,9 @@
-# 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?
- cache metadata do
%section{ id: attr, dir: dir } %section{ id: attr, dir: dir }
= @post.send(attr).to_s.html_safe = @post.public_send(attr).to_s.html_safe