From fe26ad57782f7d22c27d8d168de7fca1dddadfe8 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Mon, 21 Jan 2019 12:45:09 -0500 Subject: [PATCH] Add additional home page caching (#1610) --- app/controllers/stories_controller.rb | 3 +- .../articles/_sidebar_additional.html.erb | 215 +++++++++--------- 2 files changed, 111 insertions(+), 107 deletions(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 0e5fcac28..281aa09df 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -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 diff --git a/app/views/articles/_sidebar_additional.html.erb b/app/views/articles/_sidebar_additional.html.erb index b24dd14f3..af5908ad9 100644 --- a/app/views/articles/_sidebar_additional.html.erb +++ b/app/views/articles/_sidebar_additional.html.erb @@ -18,149 +18,154 @@ <% end %> - <% if @sidebar_ad %> -
-
- <%= @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 %> +
+
+ <%= @sidebar_ad.processed_html.html_safe %> +
-
- <% end %> - <% ApplicationConfig["TRENDING_TAGS"].split(",").each do |tag| %> + <% end %> + <% ApplicationConfig["TRENDING_TAGS"].split(",").each do |tag| %> +
+
+

#<%= tag %>

+
+
+ + MAKE A #<%= tag.upcase %> POST +
+
+ <% end %> + <% if Article.active_help.any? %> +
+
+

#help

+
+
+ + ASK FOR HELP +
+
+ <% end %> + <% if Article.active_threads(["ama"], Timeframer.new(params[:timeframe]).datetime).any? %> +
+
+

#ama

+
+
+ + START AN "ASK ME ANYTHING" +
+
+ <% end %> + <% if Article.active_threads(["challenge"], Timeframer.new(params[:timeframe]).datetime).any? %> +
+
+

#challenge

+
+
+ + CREATE A CHALLENGE +
+
+ <% end %>
-

#<%= tag %>

+

#discuss

- MAKE A #<%= tag.upcase %> POST + START A DISCUSSION
- <% end %> - <% if Article.active_help.any? %>
-

#help

+

#explainlikeimfive

- ASK FOR HELP -
-
- <% end %> - <% if Article.active_threads(["ama"], Timeframer.new(params[:timeframe]).datetime).any? %> -
-
-

#ama

-
-
- - START AN "ASK ME ANYTHING" + ASK FOR AN EXPLANATION
- <% end %> - <% if Article.active_threads(["challenge"], Timeframer.new(params[:timeframe]).datetime).any? %>
-

#challenge

+

#healthydebate

- CREATE A CHALLENGE + START A DEBATE +
+
+
+
+

#meta

+
+
+ + START A META DISCUSSION
<% end %> -
-
-

#discuss

-
-
- - START A DISCUSSION -
-
-
-
-

#explainlikeimfive

-
-
- - ASK FOR AN EXPLANATION -
-
-
-
-

#healthydebate

-
-
- - START A DEBATE -
-
-
-
-

#meta

-
-
- - START A META DISCUSSION -
-
<% if user_signed_in? %> -
-
-

latest podcasts

-
-
- <% @podcast_episodes.each do |ep| %> - + <% end %> <% else %> <% cache("seo-boostable-posts-homepage", :expires_in => 18.hours) do %> <% @boostable_posts = Article.seo_boostable %>