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 <bendhalpern@gmail.com>

* Update app/views/articles/show.html.erb

Co-Authored-By: benhalpern <bendhalpern@gmail.com>

* Update app/views/articles/show.html.erb

Co-Authored-By: benhalpern <bendhalpern@gmail.com>
This commit is contained in:
Ben Halpern 2019-01-20 15:50:57 -05:00 committed by GitHub
parent 36b42b2ccd
commit 6e4259baaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -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

View file

@ -162,13 +162,17 @@
</div>
</header>
<% if @article.collection_id %>
<%= render "articles/collection", position: "top" %>
<% cache("article-series-collection-#{@article.collection_id}") do %>
<%= render "articles/collection", position: "top" %>
<% end %>
<% end %>
<div class="body" data-article-id="<%= @article.id %>" id="article-body" itemprop="articleBody">
<%= @article.processed_html.html_safe %>
</div>
<% 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' %>
</article>
@ -242,4 +246,4 @@
<%= GistTag.script.html_safe %>
<%= RunkitTag.script.html_safe %>
</script>
<% end %>
<% end %>