PERF: Cache About#stats.

This commit is contained in:
Guo Xiang Tan
2015-07-07 12:52:19 +08:00
parent 8be37193ee
commit b0ea6764e0
12 changed files with 121 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
require_dependency 'mem_info'
class AdminDashboardData
include StatsCacheable
GLOBAL_REPORTS ||= [
'visits',
@@ -57,13 +58,7 @@ class AdminDashboardData
def self.fetch_stats
AdminDashboardData.new
end
def self.fetch_cached_stats
# The DashboardStats job is responsible for generating and caching this.
stats = $redis.get(stats_cache_key)
stats ? JSON.parse(stats) : nil
AdminDashboardData.new.as_json
end
def self.stats_cache_key
@@ -96,11 +91,6 @@ class AdminDashboardData
source.map { |type| Report.find(type).as_json }
end
# Could be configurable, multisite need to support it.
def self.recalculate_interval
30 # minutes
end
def rails_env_check
I18n.t("dashboard.rails_env_warning", env: Rails.env) unless Rails.env.production?
end