Change impression count to exclude when :referrer is nil

This commit is contained in:
Christophe Vilayphiou 2012-05-18 14:13:11 +08:00
parent d9c12ea5a4
commit 7c6b807170
4 changed files with 11 additions and 9 deletions

View File

@ -30,7 +30,7 @@ class Admin::DashboardsController < ApplicationController
module_app_class = module_app.classify.constantize module_app_class = module_app.classify.constantize
objects = module_app_class.order_by(:updated_at, :desc).limit(10) objects = module_app_class.order_by(:updated_at, :desc).limit(10)
objects.each do |object| objects.each do |object|
a.merge!(object => object.updated_at) a.merge!(object => object.updated_at) unless (object.archived rescue nil)
end end
end end
sorted_objects = a.sort {|a,b| b[1]<=>a[1]} sorted_objects = a.sort {|a,b| b[1]<=>a[1]}
@ -43,7 +43,7 @@ class Admin::DashboardsController < ApplicationController
module_app_class = module_app.classify.constantize module_app_class = module_app.classify.constantize
objects = module_app_class.order_by(:view_count, :desc).limit(10) objects = module_app_class.order_by(:view_count, :desc).limit(10)
objects.each do |object| objects.each do |object|
a.merge!(object => object.view_count) if object.view_count > 0 a.merge!(object => object.view_count) if object.view_count > 0 && (!object.archived rescue true)
end end
end end
sorted_objects = a.sort {|a,b| b[1]<=>a[1]} sorted_objects = a.sort {|a,b| b[1]<=>a[1]}

View File

@ -181,7 +181,7 @@ module ApplicationHelper
end end
def display_visitors(options={}) def display_visitors(options={})
Impression.where(options).distinct(:session_hash).count Impression.where(options).and(:referrer.ne => nil).distinct(:session_hash).count
end end
def display_visitors_today def display_visitors_today

View File

@ -8,7 +8,7 @@ defaults: &defaults
development: development:
<<: *defaults <<: *defaults
database: prototype_r4_ldap0229 database: bob
test: test:
<<: *defaults <<: *defaults
@ -22,4 +22,4 @@ production:
# password: <%= ENV['MONGOID_PASSWORD'] %> # password: <%= ENV['MONGOID_PASSWORD'] %>
# database: <%= ENV['MONGOID_DATABASE'] %> # database: <%= ENV['MONGOID_DATABASE'] %>
<<: *defaults <<: *defaults
database: prototype_r4_ldap0229 database: prototype_r4_development

View File

@ -27,11 +27,13 @@ class Impression
private private
def update_impressions_counter_cache def update_impressions_counter_cache
impressionable_class = self.impressionable_type.constantize if self.referrer
impressionable_class = self.impressionable_type.constantize
if impressionable_class.impressionist_counter_cache_options if impressionable_class.impressionist_counter_cache_options
resouce = impressionable_class.find(self.impressionable_id) resouce = impressionable_class.find(self.impressionable_id)
resouce.try(:update_impressionist_counter_cache) resouce.try(:update_impressionist_counter_cache)
end
end end
end end
end end