update dashboard for better performance
This commit is contained in:
parent
e0b22e11bb
commit
fe2c1a9235
|
@ -248,15 +248,24 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def get_month_traffic
|
||||
result = []
|
||||
(0..30).each do |i|
|
||||
visits = Impression.where( created_at: {
|
||||
'$gte' => Time.now.beginning_of_day-i.days,
|
||||
'$lte' => Time.now.end_of_day-i.days}
|
||||
).count
|
||||
result.push([ Time.now.beginning_of_day-i.days, visits])
|
||||
site = Site.first
|
||||
if site.month_traffic_cache.blank? or (site.month_traffic_cache['updated_at'] < (Time.now-1.day) rescue true)
|
||||
site.month_traffic_cache = {}
|
||||
|
||||
site.month_traffic_cache['result'] = []
|
||||
(1..30).each do |i|
|
||||
visits = Impression.where( created_at: {
|
||||
'$gte' => Time.now.beginning_of_day-i.days,
|
||||
'$lte' => Time.now.end_of_day-i.days}
|
||||
).distinct(:request_hash).count
|
||||
site.month_traffic_cache['result'].push([ Time.now.beginning_of_day-i.days, visits])
|
||||
end
|
||||
|
||||
site.month_traffic_cache['updated_at'] = Time.now
|
||||
site.save
|
||||
end
|
||||
[:name=> t(:visitors_count),:data=>result]
|
||||
|
||||
[:name=> t(:visitors_count),:data=>site.month_traffic_cache['result']]
|
||||
end
|
||||
|
||||
# def get_today_traffic
|
||||
|
|
|
@ -51,6 +51,8 @@ class Site
|
|||
field :store_confirmation, :type => Boolean, :default => false
|
||||
field :meta_viewport, :type => Boolean, :default => false
|
||||
|
||||
field :month_traffic_cache
|
||||
|
||||
belongs_to :design
|
||||
has_many :site_metas, :autosave => true, :dependent => :destroy
|
||||
validate :in_use_locales, :minimum_enabled_locales
|
||||
|
|
Loading…
Reference in New Issue