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)
|
||||||
visits = Impression.where( created_at: {
|
site.month_traffic_cache = {}
|
||||||
'$gte' => Time.now.beginning_of_day-i.days,
|
|
||||||
'$lte' => Time.now.end_of_day-i.days}
|
site.month_traffic_cache['result'] = []
|
||||||
).count
|
(1..30).each do |i|
|
||||||
result.push([ Time.now.beginning_of_day-i.days, visits])
|
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
|
end
|
||||||
[:name=> t(:visitors_count),:data=>result]
|
|
||||||
|
[: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