5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-02 12:56:07 +00:00

usar caché!

This commit is contained in:
f 2020-05-11 17:28:38 -03:00
parent c7f3400c1e
commit eb4cf60596
7 changed files with 112 additions and 95 deletions

View file

@ -14,12 +14,16 @@ class PostsController < ApplicationController
@posts = @site.posts(lang: lang) @posts = @site.posts(lang: lang)
@posts.sort_by!(:order, :date).reverse! @posts.sort_by!(:order, :date).reverse!
@usuarie = @site.usuarie? current_usuarie @usuarie = @site.usuarie? current_usuarie
fresh_when @posts
end end
def show def show
@site = find_site @site = find_site
@post = @site.posts(lang: lang).find params[:id] @post = @site.posts(lang: lang).find params[:id]
authorize @post authorize @post
fresh_when @post
end end
def new def new

View file

@ -9,6 +9,8 @@ class SitesController < ApplicationController
def index def index
authorize Site authorize Site
@sites = current_usuarie.sites.order(:title) @sites = current_usuarie.sites.order(:title)
fresh_when @sites
end end
# No tenemos propiedades de un sitio aún, así que vamos al listado de # No tenemos propiedades de un sitio aún, así que vamos al listado de

View file

@ -70,6 +70,11 @@ class Post < OpenStruct
document.read! if File.exist? document.path document.read! if File.exist? document.path
end end
# Devuelve una llave para poder guardar el post en una cache
def cache_key
'posts/' + uuid.value
end
# TODO: Convertir a UUID? # TODO: Convertir a UUID?
def id def id
path.basename path.basename

View file

@ -7,15 +7,16 @@
%main.row %main.row
%aside.menu.col-md-3 %aside.menu.col-md-3
%h1 - cache @site do
= link_to @site.title, @site.url %h1
%p.lead= @site.description = link_to @site.title, @site.url
%p.lead= @site.description
%h3= t('posts.new') %h3= t('posts.new')
%ul %ul
- @site.layouts.to_h.keys.each do |layout| - @site.layouts.to_h.keys.each do |layout|
%li= link_to @site.i18n.dig('layouts', layout.to_s) || layout.to_s.humanize, %li= link_to @site.i18n.dig('layouts', layout.to_s) || layout.to_s.humanize,
new_site_post_path(@site, layout: layout) new_site_post_path(@site, layout: layout)
- if policy(@site).edit? - if policy(@site).edit?
= link_to t('sites.edit.btn', site: @site.title), = link_to t('sites.edit.btn', site: @site.title),
@ -43,43 +44,47 @@
- if @layout - if @layout
- next unless post.layout.name == @layout - next unless post.layout.name == @layout
- next unless @usuarie || policy(post).show? - next unless @usuarie || policy(post).show?
%tr -#
%td TODO: Solo les usuaries cachean porque tenemos que separar
.handle les botones por permisos.
= image_tag 'arrows-alt-v.svg' - cache_if @site.usuarie?(current_usuarie), post do
-# Orden más alto es mayor prioridad %tr
= hidden_field 'post[reorder]', post.uuid.value, %td
value: @posts.length - i, class: 'reorder' .handle
%td = image_tag 'arrows-alt-v.svg'
%small -# Orden más alto es mayor prioridad
= link_to @site.i18n.dig('layouts', post.layout.name.to_s) || post.layout.name.to_s.humanize, = hidden_field 'post[reorder]', post.uuid.value,
site_posts_path(@site, layout: post.layout.name) value: @posts.length - i, class: 'reorder'
%br/ %td
= link_to post.title.value, %small
site_post_path(@site, post.id) = link_to @site.i18n.dig('layouts', post.layout.name.to_s) || post.layout.name.to_s.humanize,
- if post.attributes.include? :draft site_posts_path(@site, layout: post.layout.name)
- if post.draft.value %br/
%span.badge.badge-primary = link_to post.title.value,
= post_label_t(:draft, post: post) site_post_path(@site, post.id)
- if post.attributes.include? :categories - if post.attributes.include? :draft
- unless post.categories.value.empty? - if post.draft.value
%br %span.badge.badge-primary
%small = post_label_t(:draft, post: post)
- post.categories.value.each do |c| - if post.attributes.include? :categories
= link_to c, site_posts_path(@site, category: c) - unless post.categories.value.empty?
%br
%small
- post.categories.value.each do |c|
= link_to c, site_posts_path(@site, category: c)
%td %td
= post.date.value.strftime('%F') = post.date.value.strftime('%F')
%br/ %br/
= post.try(:order).try(:value) = post.try(:order).try(:value)
%td %td
- if @usuarie || policy(post).edit? - if @usuarie || policy(post).edit?
= link_to t('posts.edit'), = link_to t('posts.edit'),
edit_site_post_path(@site, post.id), edit_site_post_path(@site, post.id),
class: 'btn' class: 'btn'
- if @usuarie || policy(post).destroy? - if @usuarie || policy(post).destroy?
= link_to t('posts.destroy'), = link_to t('posts.destroy'),
site_post_path(@site, post.id), site_post_path(@site, post.id),
class: 'btn', class: 'btn',
method: :delete, method: :delete,
data: { confirm: t('posts.confirm_destroy') } data: { confirm: t('posts.confirm_destroy') }

View file

@ -15,46 +15,50 @@
%table.table.table-condensed %table.table.table-condensed
%tbody %tbody
- @sites.each do |site| - @sites.each do |site|
%tr -#
%td TODO: Solo les usuaries cachean porque tenemos que separar
%h2 les botones por permisos.
- if policy(site).show? - cache_if site.usuarie?(current_usuarie), site do
= link_to site.title, site_path(site) %tr
%td
%h2
- if policy(site).show?
= link_to site.title, site_path(site)
- else
= site.title
%p.lead= site.description
%br
= link_to t('.visit'), site.url, class: 'btn'
- if current_usuarie.rol_for_site(site).temporal
= button_to t('sites.invitations.accept'),
site_usuaries_accept_invitation_path(site),
data: { toggle: 'tooltip' },
title: t('help.sites.invitations.accept'),
method: :patch,
class: 'btn'
= button_to t('sites.invitations.reject'),
site_usuaries_reject_invitation_path(site),
data: { toggle: 'tooltip' },
title: t('help.sites.invitations.reject'),
method: :patch,
class: 'btn'
- else - else
= site.title - if policy(site).show?
%p.lead= site.description = render 'layouts/btn_with_tooltip',
%br tooltip: t('help.sites.edit_posts'),
= link_to t('.visit'), site.url, class: 'btn' type: 'success',
- if current_usuarie.rol_for_site(site).temporal link: site_path(site),
= button_to t('sites.invitations.accept'), text: t('sites.posts')
site_usuaries_accept_invitation_path(site), - if policy(SiteUsuarie.new(site, current_usuarie)).index?
data: { toggle: 'tooltip' }, = render 'layouts/btn_with_tooltip',
title: t('help.sites.invitations.accept'), tooltip: t('usuaries.index.help.self'),
method: :patch, text: t('usuaries.index.title'),
class: 'btn' type: 'info',
= button_to t('sites.invitations.reject'), link: site_usuaries_path(site)
site_usuaries_reject_invitation_path(site), - if policy(site).pull? && site.repository.needs_pull?
data: { toggle: 'tooltip' }, = render 'layouts/btn_with_tooltip',
title: t('help.sites.invitations.reject'), tooltip: t('help.sites.pull'),
method: :patch, text: t('.pull'),
class: 'btn' type: 'info',
- else link: site_pull_path(site)
- if policy(site).show? = render 'sites/build', site: site
= render 'layouts/btn_with_tooltip',
tooltip: t('help.sites.edit_posts'),
type: 'success',
link: site_path(site),
text: t('sites.posts')
- if policy(SiteUsuarie.new(site, current_usuarie)).index?
= render 'layouts/btn_with_tooltip',
tooltip: t('usuaries.index.help.self'),
text: t('usuaries.index.title'),
type: 'info',
link: site_usuaries_path(site)
- if policy(site).pull? && site.repository.needs_pull?
= render 'layouts/btn_with_tooltip',
tooltip: t('help.sites.pull'),
text: t('.pull'),
type: 'info',
link: site_pull_path(site)
= render 'sites/build', site: site

View file

@ -21,7 +21,7 @@ Rails.application.configure do
if Rails.root.join('tmp/caching-dev.txt').exist? if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true config.action_controller.perform_caching = true
config.cache_store = :redis_cache_store config.cache_store = :redis_cache_store, { url: ENV['REDIS_SERVER'] }
config.public_file_server.headers = { config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}" 'Cache-Control' => "public, max-age=#{2.days.to_i}"
} }

View file

@ -29,13 +29,10 @@ Rails.application.configure do
# Compress CSS using a preprocessor. # Compress CSS using a preprocessor.
config.assets.css_compressor = :sass config.assets.css_compressor = :sass
# rubocop:disable Lint/HandleExceptions
begin begin
config.assets.js_compressor = Uglifier.new(harmony: true) config.assets.js_compressor = Uglifier.new(harmony: true)
rescue NameError rescue NameError
end end
# rubocop:enable Lint/HandleExceptions
# Do not fallback to assets pipeline if a precompiled asset is missed. # Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false config.assets.compile = false
@ -63,7 +60,7 @@ Rails.application.configure do
config.log_tags = [:request_id] config.log_tags = [:request_id]
# Use a different cache store in production. # Use a different cache store in production.
config.cache_store = :redis_cache_store config.cache_store = :redis_cache_store, { url: ENV['REDIS_SERVER'] }
# Use a real queuing backend for Active Job (and separate queues per # Use a real queuing backend for Active Job (and separate queues per
# environment) # environment)
@ -142,7 +139,7 @@ Rails.application.configure do
config.middleware.use ExceptionNotification::Rack, config.middleware.use ExceptionNotification::Rack,
email: { email: {
email_prefix: '[ERROR]', email_prefix: '[ERROR] ',
sender_address: ENV['DEFAULT_FROM'], sender_address: ENV['DEFAULT_FROM'],
exception_recipients: ENV['EXCEPTION_TO'] exception_recipients: ENV['EXCEPTION_TO']
} }