usar caché!
This commit is contained in:
parent
c7f3400c1e
commit
eb4cf60596
7 changed files with 112 additions and 95 deletions
|
@ -14,12 +14,16 @@ class PostsController < ApplicationController
|
|||
@posts = @site.posts(lang: lang)
|
||||
@posts.sort_by!(:order, :date).reverse!
|
||||
@usuarie = @site.usuarie? current_usuarie
|
||||
|
||||
fresh_when @posts
|
||||
end
|
||||
|
||||
def show
|
||||
@site = find_site
|
||||
@post = @site.posts(lang: lang).find params[:id]
|
||||
authorize @post
|
||||
|
||||
fresh_when @post
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
|
@ -9,6 +9,8 @@ class SitesController < ApplicationController
|
|||
def index
|
||||
authorize Site
|
||||
@sites = current_usuarie.sites.order(:title)
|
||||
|
||||
fresh_when @sites
|
||||
end
|
||||
|
||||
# No tenemos propiedades de un sitio aún, así que vamos al listado de
|
||||
|
|
|
@ -70,6 +70,11 @@ class Post < OpenStruct
|
|||
document.read! if File.exist? document.path
|
||||
end
|
||||
|
||||
# Devuelve una llave para poder guardar el post en una cache
|
||||
def cache_key
|
||||
'posts/' + uuid.value
|
||||
end
|
||||
|
||||
# TODO: Convertir a UUID?
|
||||
def id
|
||||
path.basename
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
%main.row
|
||||
%aside.menu.col-md-3
|
||||
- cache @site do
|
||||
%h1
|
||||
= link_to @site.title, @site.url
|
||||
%p.lead= @site.description
|
||||
|
@ -43,6 +44,10 @@
|
|||
- if @layout
|
||||
- next unless post.layout.name == @layout
|
||||
- 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
|
||||
%td
|
||||
.handle
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
%table.table.table-condensed
|
||||
%tbody
|
||||
- @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
|
||||
%td
|
||||
%h2
|
||||
|
|
|
@ -21,7 +21,7 @@ Rails.application.configure do
|
|||
if Rails.root.join('tmp/caching-dev.txt').exist?
|
||||
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 = {
|
||||
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
||||
}
|
||||
|
|
|
@ -29,13 +29,10 @@ Rails.application.configure do
|
|||
|
||||
# Compress CSS using a preprocessor.
|
||||
config.assets.css_compressor = :sass
|
||||
|
||||
# rubocop:disable Lint/HandleExceptions
|
||||
begin
|
||||
config.assets.js_compressor = Uglifier.new(harmony: true)
|
||||
rescue NameError
|
||||
end
|
||||
# rubocop:enable Lint/HandleExceptions
|
||||
|
||||
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
||||
config.assets.compile = false
|
||||
|
@ -63,7 +60,7 @@ Rails.application.configure do
|
|||
config.log_tags = [:request_id]
|
||||
|
||||
# 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
|
||||
# environment)
|
||||
|
|
Loading…
Reference in a new issue