From 4e7e4cee7d751c25a2b2b9da2f72288725ce8195 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 7 Apr 2016 22:28:31 +0800 Subject: [PATCH] PERF: Rendering crawler's template is expensive. --- app/controllers/about_controller.rb | 2 -- app/helpers/application_helper.rb | 6 ++++- app/views/about/index.html.erb | 36 +++++++++++++++++------------ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index a3957ebda99..0d53930bcd3 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c007b461dfc..16b86ab2624 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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? diff --git a/app/views/about/index.html.erb b/app/views/about/index.html.erb index d13b4e78614..5f8bb079b86 100644 --- a/app/views/about/index.html.erb +++ b/app/views/about/index.html.erb @@ -1,3 +1,5 @@ +<% if crawler_layout? %> + <% content_for :title do %><%=t "about" %><% end %>
@@ -52,6 +54,8 @@ <% end %> + <%- stats = About.fetch_cached_stats %> +

<%=t 'js.about.stats' %>

@@ -64,37 +68,39 @@ <%=t 'js.about.topic_count' %> - <%= @about.stats[:topic_count] %> - <%= @about.stats[:topics_7_days] %> - <%= @about.stats[:topics_30_days] %> + <%= stats["topic_count"] %> + <%= stats["topics_7_days"] %> + <%= stats["topics_30_days"] %> <%=t 'js.about.post_count' %> - <%= @about.stats[:post_count] %> - <%= @about.stats[:posts_7_days] %> - <%= @about.stats[:posts_30_days] %> + <%= stats["post_count"] %> + <%= stats["posts_7_days"] %> + <%= stats["posts_30_days"] %> <%=t 'js.about.user_count' %> - <%= @about.stats[:user_count] %> - <%= @about.stats[:users_7_days] %> - <%= @about.stats[:users_30_days] %> + <%= stats["user_count"] %> + <%= stats["users_7_days"] %> + <%= stats["users_30_days"] %> <%=t 'js.about.active_user_count' %> — - <%= @about.stats[:active_users_7_days] %> - <%= @about.stats[:active_users_30_days] %> + <%= stats["active_users_7_days"] %> + <%= stats["active_users_30_days"] %> <%=t 'js.about.like_count' %> - <%= @about.stats[:like_count] %> - <%= @about.stats[:likes_7_days] %> - <%= @about.stats[:likes_30_days] %> + <%= stats["like_count"] %> + <%= stats["likes_7_days"] %> + <%= stats["likes_30_days"] %>

-
\ No newline at end of file +
+ +<% end %>