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