5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-04 15:25:45 +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,6 +7,7 @@
%main.row %main.row
%aside.menu.col-md-3 %aside.menu.col-md-3
- cache @site do
%h1 %h1
= link_to @site.title, @site.url = link_to @site.title, @site.url
%p.lead= @site.description %p.lead= @site.description
@ -43,6 +44,10 @@
- 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?
-#
TODO: Solo les usuaries cachean porque tenemos que separar
les botones por permisos.
- cache_if @site.usuarie?(current_usuarie), post do
%tr %tr
%td %td
.handle .handle

View file

@ -15,6 +15,10 @@
%table.table.table-condensed %table.table.table-condensed
%tbody %tbody
- @sites.each do |site| - @sites.each do |site|
-#
TODO: Solo les usuaries cachean porque tenemos que separar
les botones por permisos.
- cache_if site.usuarie?(current_usuarie), site do
%tr %tr
%td %td
%h2 %h2

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']
} }