Cache data on /mod (#5315) [deploy]
This commit is contained in:
parent
a716cf2756
commit
df796f7e07
4 changed files with 36 additions and 21 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -12,29 +12,34 @@
|
|||
}
|
||||
</style>
|
||||
<% end %>
|
||||
<div class="mod-index-hero">
|
||||
<h1><%= "#" + @tag.name.titleize if @tag %> Moderators</h1>
|
||||
<h2>We build the <%= ApplicationConfig["COMMUNITY_NAME"] %> Community</h2>
|
||||
<div class="mod-index-hero-data-pod">
|
||||
<div class="mod-index-hero-data-pod-number">
|
||||
<%= 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 %>
|
||||
<div class="mod-index-hero">
|
||||
<h1><%= "#" + @tag.name.titleize if @tag %> Moderators</h1>
|
||||
<h2>We build the <%= ApplicationConfig["COMMUNITY_NAME"] %> Community</h2>
|
||||
<div class="mod-index-hero-data-pod">
|
||||
<div class="mod-index-hero-data-pod-number">
|
||||
<%= 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) %>
|
||||
</div>
|
||||
Posts This Week
|
||||
</div>
|
||||
Posts This Week
|
||||
</div>
|
||||
<% plucked_article_ids = Article.cached_tagged_with(@tag).pluck(:id) if @tag %>
|
||||
<div class="mod-index-hero-data-pod">
|
||||
<div class="mod-index-hero-data-pod-number">
|
||||
<%= 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 %>
|
||||
<div class="mod-index-hero-data-pod">
|
||||
<div class="mod-index-hero-data-pod-number">
|
||||
<%= 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) %>
|
||||
</div>
|
||||
Comments This Week
|
||||
</div>
|
||||
Comments This Week
|
||||
</div>
|
||||
<div class="mod-index-hero-data-pod">
|
||||
<div class="mod-index-hero-data-pod-number">
|
||||
<%= 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) %>
|
||||
<div class="mod-index-hero-data-pod">
|
||||
<div class="mod-index-hero-data-pod-number">
|
||||
<%= 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) %>
|
||||
</div>
|
||||
Reactions This Week
|
||||
</div>
|
||||
<div class="mod-index-hero-sub">
|
||||
<em>Data as of <%= Time.current %></em>
|
||||
</div>
|
||||
Reactions This Week
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="mod-index-header">
|
||||
<div class="mod-index-header-top-filters">
|
||||
<a href="<%= request.path %>" class="<%= "mod-index-top-filter-link--active" if params[:state].blank? %>">Base Feed</a>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue