PERF: Rendering crawler's template is expensive.

This commit is contained in:
Guo Xiang Tan 2016-04-07 22:28:31 +08:00 committed by Régis Hanol
parent 3d4cdd7040
commit 4e7e4cee7d
3 changed files with 26 additions and 18 deletions

View File

@ -9,8 +9,6 @@ class AboutController < ApplicationController
respond_to do |format|
format.html do
# @list = list
# store_preloaded(list.preload_key, MultiJson.dump(TopicListSerializer.new(list, scope: guardian)))
render :index
end
format.json do

View File

@ -169,8 +169,12 @@ module ApplicationHelper
MobileDetection.resolve_mobile_view!(request.user_agent,params,session)
end
def crawler_layout?
controller.try(:use_crawler_layout?)
end
def include_crawler_content?
controller.try(:use_crawler_layout?) || !mobile_view?
crawler_layout? || !mobile_view?
end
def mobile_device?

View File

@ -1,3 +1,5 @@
<% if crawler_layout? %>
<% content_for :title do %><%=t "about" %><% end %>
<section itemscope itemtype="https://schema.org/AboutPage">
@ -52,6 +54,8 @@
</div>
<% end %>
<%- stats = About.fetch_cached_stats %>
<section class='about stats'>
<h2><%=t 'js.about.stats' %></h2>
@ -64,33 +68,33 @@
</tr>
<tr>
<td class='title'><%=t 'js.about.topic_count' %></td>
<td><%= @about.stats[:topic_count] %></td>
<td><%= @about.stats[:topics_7_days] %></td>
<td><%= @about.stats[:topics_30_days] %></td>
<td><%= stats["topic_count"] %></td>
<td><%= stats["topics_7_days"] %></td>
<td><%= stats["topics_30_days"] %></td>
</tr>
<tr>
<td><%=t 'js.about.post_count' %></td>
<td><%= @about.stats[:post_count] %></td>
<td><%= @about.stats[:posts_7_days] %></td>
<td><%= @about.stats[:posts_30_days] %></td>
<td><%= stats["post_count"] %></td>
<td><%= stats["posts_7_days"] %></td>
<td><%= stats["posts_30_days"] %></td>
</tr>
<tr>
<td><%=t 'js.about.user_count' %></td>
<td><%= @about.stats[:user_count] %></td>
<td><%= @about.stats[:users_7_days] %></td>
<td><%= @about.stats[:users_30_days] %></td>
<td><%= stats["user_count"] %></td>
<td><%= stats["users_7_days"] %></td>
<td><%= stats["users_30_days"] %></td>
</tr>
<tr>
<td><%=t 'js.about.active_user_count' %></td>
<td>&mdash;</td>
<td><%= @about.stats[:active_users_7_days] %></td>
<td><%= @about.stats[:active_users_30_days] %></td>
<td><%= stats["active_users_7_days"] %></td>
<td><%= stats["active_users_30_days"] %></td>
</tr>
<tr>
<td><%=t 'js.about.like_count' %></td>
<td><%= @about.stats[:like_count] %></td>
<td><%= @about.stats[:likes_7_days] %></td>
<td><%= @about.stats[:likes_30_days] %></td>
<td><%= stats["like_count"] %></td>
<td><%= stats["likes_7_days"] %></td>
<td><%= stats["likes_30_days"] %></td>
</tr>
</table>
</section>
@ -98,3 +102,5 @@
</section>
<br/>
<br/>
<% end %>