From df796f7e077801501b0de3579e0bb68b95d3c463 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Tue, 31 Dec 2019 10:18:55 -0500 Subject: [PATCH] Cache data on /mod (#5315) [deploy] --- app/assets/stylesheets/moderators.scss | 8 ++++- app/controllers/moderations_controller.rb | 2 +- app/views/moderations/index.html.erb | 43 +++++++++++++---------- spec/requests/moderations_spec.rb | 4 +++ 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/app/assets/stylesheets/moderators.scss b/app/assets/stylesheets/moderators.scss index e3e321902..77d7fed8c 100644 --- a/app/assets/stylesheets/moderators.scss +++ b/app/assets/stylesheets/moderators.scss @@ -7,7 +7,10 @@ text-align: center; background: #d4fffe; h1 { - font-size: 4em; + font-size: calc(1.8em + 2vw); + } + h2 { + font-size: calc(0.9em + 1vw); } a { text-decoration: underline; @@ -39,6 +42,9 @@ } } } + .mod-index-hero-sub { + font-size: 0.9em; + } } .mod-index-header { diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index c5c9bca39..19375e3c1 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -11,7 +11,7 @@ class ModerationsController < ApplicationController @articles = @articles.cached_tagged_with(params[:tag]) if params[:tag].present? @articles = @articles.where("nth_published_by_author > 0 AND nth_published_by_author < 4 AND published_at > ?", 7.days.ago) if params[:state] == "new-authors" @articles = @articles.decorate - @tag = Tag.find_by(name: params[:tag]) + @tag = Tag.find_by(name: params[:tag]) || not_found if params[:tag].present? end def article diff --git a/app/views/moderations/index.html.erb b/app/views/moderations/index.html.erb index c1c09cb94..642fbe615 100644 --- a/app/views/moderations/index.html.erb +++ b/app/views/moderations/index.html.erb @@ -12,29 +12,34 @@ } <% end %> -
-

<%= "#" + @tag.name.titleize if @tag %> Moderators

-

We build the <%= ApplicationConfig["COMMUNITY_NAME"] %> Community

-
-
- <%= number_with_delimiter(@tag ? Article.cached_tagged_with(@tag).published.where("published_at > ?", 7.days.ago).size : Article.published.where("published_at > ?", 7.days.ago).size) %> + <% cache("mod-data-header-#{params[:tag]}", expires_in: 6.hours) do %> +
+

<%= "#" + @tag.name.titleize if @tag %> Moderators

+

We build the <%= ApplicationConfig["COMMUNITY_NAME"] %> Community

+
+
+ <%= number_with_delimiter(@tag ? Article.cached_tagged_with(@tag).published.where("published_at > ?", 7.days.ago).size : Article.published.where("published_at > ?", 7.days.ago).size) %> +
+ Posts This Week
- Posts This Week -
- <% plucked_article_ids = Article.cached_tagged_with(@tag).pluck(:id) if @tag %> -
-
- <%= number_with_delimiter(@tag ? Comment.where(commentable_id: plucked_article_ids ).where("created_at > ?", 7.days.ago).size : Comment.where("created_at > ?", 7.days.ago).size) %> + <% plucked_article_ids = Article.cached_tagged_with(@tag).pluck(:id) if @tag %> +
+
+ <%= number_with_delimiter(@tag ? Comment.where(commentable_id: plucked_article_ids ).where("created_at > ?", 7.days.ago).size : Comment.where("created_at > ?", 7.days.ago).size) %> +
+ Comments This Week
- Comments This Week -
-
-
- <%= number_with_delimiter(@tag ? Reaction.where(reactable_id: plucked_article_ids ).where("created_at > ?", 7.days.ago).size : Reaction.where("created_at > ?", 7.days.ago).size) %> +
+
+ <%= number_with_delimiter(@tag ? Reaction.where(reactable_id: plucked_article_ids ).where("created_at > ?", 7.days.ago).size : Reaction.where("created_at > ?", 7.days.ago).size) %> +
+ Reactions This Week +
+
+ Data as of <%= Time.current %>
- Reactions This Week
-
+ <% end %>
">Base Feed diff --git a/spec/requests/moderations_spec.rb b/spec/requests/moderations_spec.rb index a64852591..e14299708 100644 --- a/spec/requests/moderations_spec.rb +++ b/spec/requests/moderations_spec.rb @@ -68,5 +68,9 @@ RSpec.describe "Moderations", type: :request do get "/mod/#{article.tags.first}" expect(response.body).to include("#" + article.tags.first.name.titleize) end + + it "returns not found for inapprpriate tags" do + expect { get "/mod/dsdsdsweweedsdseweww" }.to raise_exception(ActiveRecord::RecordNotFound) + end end end