From 6e4259baafc94c2a6d993c84879acc11f5ab63b7 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Sun, 20 Jan 2019 15:50:57 -0500 Subject: [PATCH] Cache collection so it doesn't have to be re-fetched (#1576) * Cache collection so it doesn't have to be re-fetched * Update app/views/articles/show.html.erb Co-Authored-By: benhalpern * Update app/views/articles/show.html.erb Co-Authored-By: benhalpern * Update app/views/articles/show.html.erb Co-Authored-By: benhalpern --- app/labor/cache_buster.rb | 8 +++++--- app/views/articles/show.html.erb | 12 ++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/labor/cache_buster.rb b/app/labor/cache_buster.rb index 7d9d8549c..72a76b0dd 100644 --- a/app/labor/cache_buster.rb +++ b/app/labor/cache_buster.rb @@ -50,9 +50,11 @@ class CacheBuster bust_tag_pages(article) bust("/api/articles/#{article.id}") bust("/api/articles/by_path?url=#{article.path}") - - article.collection&.articles&.find_each do |a| - bust(a.path) + if article.collection_id + article.collection&.articles&.find_each do |a| + bust(a.path) + end + Rails.cache.delete "views/article-series-collection-#{article.collection_id}" end end diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb index 7f3f8120d..ced032236 100644 --- a/app/views/articles/show.html.erb +++ b/app/views/articles/show.html.erb @@ -162,13 +162,17 @@ <% if @article.collection_id %> - <%= render "articles/collection", position: "top" %> + <% cache("article-series-collection-#{@article.collection_id}") do %> + <%= render "articles/collection", position: "top" %> + <% end %> <% end %>
<%= @article.processed_html.html_safe %>
- <% if @article.body_markdown && @article.body_markdown.size > 900 %> - <%= render "articles/collection", position: "bottom" %> + <% if @article.body_markdown && @article.body_markdown.size > 900 && @article.collection_id %> + <% cache("article-series-collection-#{@article.collection_id}") do %> + <%= render "articles/collection", position: "bottom" %> + <% end %> <% end %> <%= render 'articles/actions' %> @@ -242,4 +246,4 @@ <%= GistTag.script.html_safe %> <%= RunkitTag.script.html_safe %> -<% end %> \ No newline at end of file +<% end %>