Add additional home page caching (#1610)
This commit is contained in:
parent
6c4f5ad454
commit
fe26ad5778
2 changed files with 111 additions and 107 deletions
|
|
@ -132,8 +132,7 @@ class StoriesController < ApplicationController
|
|||
@stories = @stories.decorate
|
||||
assign_podcasts
|
||||
@article_index = true
|
||||
@sidebar_ad = DisplayAd.where(approved: true, published: true, placement_area: "sidebar").first
|
||||
set_surrogate_key_header "articles", @stories.map(&:record_key)
|
||||
set_surrogate_key_header "main_app_home_page"
|
||||
response.headers["Surrogate-Control"] = "max-age=600, stale-while-revalidate=30, stale-if-error=86400"
|
||||
render template: "articles/index"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,149 +18,154 @@
|
|||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if @sidebar_ad %>
|
||||
<div class="widget">
|
||||
<div class="widget-body" style="margin-top:-6px">
|
||||
<%= @sidebar_ad.processed_html.html_safe %>
|
||||
<% cache("main-article-right-sidebar-discussions", :expires_in => 90.seconds) do %>
|
||||
<% @sidebar_ad = DisplayAd.where(approved: true, published: true, placement_area: "sidebar").first %>
|
||||
<% if @sidebar_ad %>
|
||||
<div class="widget">
|
||||
<div class="widget-body" style="margin-top:-6px">
|
||||
<%= @sidebar_ad.processed_html.html_safe %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% ApplicationConfig["TRENDING_TAGS"].split(",").each do |tag| %>
|
||||
<% end %>
|
||||
<% ApplicationConfig["TRENDING_TAGS"].split(",").each do |tag| %>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/<%= tag %>"><h4>#<%= tag %></h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads([tag], Timeframer.new(params[:timeframe]).datetime, 5).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/<%= tag %>">MAKE A #<%= tag.upcase %> POST</a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Article.active_help.any? %>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/help"><h4>#help</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_help.limit(8).pluck(:path,:title,:comments_count, :created_at).each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/help">ASK FOR HELP</a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Article.active_threads(["ama"], Timeframer.new(params[:timeframe]).datetime).any? %>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/ama"><h4>#ama</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads(["ama"], Timeframer.new(params[:timeframe]).datetime, 5).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/ama">START AN "ASK ME ANYTHING"</a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Article.active_threads(["challenge"], Timeframer.new(params[:timeframe]).datetime).any? %>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/challenge"><h4>#challenge</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads(["challenge"], Timeframer.new(params[:timeframe]).datetime, 5).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/challenge">CREATE A CHALLENGE</a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/<%= tag %>"><h4>#<%= tag %></h4></a>
|
||||
<a href="/t/discuss"><h4>#discuss</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads([tag], Timeframer.new(params[:timeframe]).datetime, 5).
|
||||
<% Article.active_threads(["discuss"], Timeframer.new(params[:timeframe]).datetime).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/<%= tag %>">MAKE A #<%= tag.upcase %> POST</a>
|
||||
<a class="cta cta-button" href="/new/discuss">START A DISCUSSION</a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Article.active_help.any? %>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/help"><h4>#help</h4></a>
|
||||
<a href="/t/explainlikeimfive"><h4>#explainlikeimfive</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_help.limit(8).pluck(:path,:title,:comments_count, :created_at).each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/help">ASK FOR HELP</a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Article.active_threads(["ama"], Timeframer.new(params[:timeframe]).datetime).any? %>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/ama"><h4>#ama</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads(["ama"], Timeframer.new(params[:timeframe]).datetime, 5).
|
||||
<% Article.active_eli5(Timeframer.new(params[:timeframe]).datetime).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/ama">START AN "ASK ME ANYTHING"</a>
|
||||
<a class="cta cta-button" href="/new/explainlikeimfive">ASK FOR AN EXPLANATION</a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if Article.active_threads(["challenge"], Timeframer.new(params[:timeframe]).datetime).any? %>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/challenge"><h4>#challenge</h4></a>
|
||||
<a href="/t/healthydebate"><h4>#healthydebate</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads(["challenge"], Timeframer.new(params[:timeframe]).datetime, 5).
|
||||
<% Article.active_threads(["healthydebate"], Timeframer.new(params[:timeframe]).datetime).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/challenge">CREATE A CHALLENGE</a>
|
||||
<a class="cta cta-button" href="/new/healthydebate">START A DEBATE</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/meta"><h4>#meta</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads(["meta"], Timeframer.new(params[:timeframe]).datetime).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/meta">START A META DISCUSSION</a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/discuss"><h4>#discuss</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads(["discuss"], Timeframer.new(params[:timeframe]).datetime).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/discuss">START A DISCUSSION</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/explainlikeimfive"><h4>#explainlikeimfive</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_eli5(Timeframer.new(params[:timeframe]).datetime).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/explainlikeimfive">ASK FOR AN EXPLANATION</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/healthydebate"><h4>#healthydebate</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads(["healthydebate"], Timeframer.new(params[:timeframe]).datetime).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/healthydebate">START A DEBATE</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="widget">
|
||||
<header>
|
||||
<a href="/t/meta"><h4>#meta</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<div class="widget-link-list">
|
||||
<% Article.active_threads(["meta"], Timeframer.new(params[:timeframe]).datetime).
|
||||
each do |plucked_article| %>
|
||||
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="cta cta-button" href="/new/meta">START A META DISCUSSION</a>
|
||||
</div>
|
||||
</div>
|
||||
<% if user_signed_in? %>
|
||||
<div class="widget" id="podcast-widget">
|
||||
<header>
|
||||
<a href="/pod"><h4>latest podcasts</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<% @podcast_episodes.each do |ep| %>
|
||||
<div class="widget-podcast-ep">
|
||||
<a href="<%= ep.path %>"><%= ep.title %>
|
||||
<div class="widget-podcast-title">
|
||||
<a href="<%= ep.podcast.path %>"><%= ep.podcast.title %>
|
||||
<% cache("featured-homepage-podcasts", :expires_in => 15.minutes) do %>
|
||||
<div class="widget" id="podcast-widget">
|
||||
<header>
|
||||
<a href="/pod"><h4>latest podcasts</h4></a>
|
||||
</header>
|
||||
<div class="widget-body">
|
||||
<% @podcast_episodes.each do |ep| %>
|
||||
<div class="widget-podcast-ep">
|
||||
<a href="<%= ep.path %>"><%= ep.title %>
|
||||
<div class="widget-podcast-title">
|
||||
<a href="<%= ep.podcast.path %>"><%= ep.podcast.title %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<a class="cta cta-button" href="/pod">VIEW ALL</a>
|
||||
<% end %>
|
||||
<a class="cta cta-button" href="/pod">VIEW ALL</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% cache("seo-boostable-posts-homepage", :expires_in => 18.hours) do %>
|
||||
<% @boostable_posts = Article.seo_boostable %>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue