From 7c6b8071709a3f4149cfa9afbaee866e613450e6 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Fri, 18 May 2012 14:13:11 +0800 Subject: [PATCH] Change impression count to exclude when :referrer is nil --- app/controllers/admin/dashboards_controller.rb | 4 ++-- app/helpers/application_helper.rb | 2 +- config/mongoid.yml | 4 ++-- .../lib/impressionist/models/mongoid/impression.rb | 10 ++++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb index 50bbd1aa..991f19af 100644 --- a/app/controllers/admin/dashboards_controller.rb +++ b/app/controllers/admin/dashboards_controller.rb @@ -30,7 +30,7 @@ class Admin::DashboardsController < ApplicationController module_app_class = module_app.classify.constantize objects = module_app_class.order_by(:updated_at, :desc).limit(10) objects.each do |object| - a.merge!(object => object.updated_at) + a.merge!(object => object.updated_at) unless (object.archived rescue nil) end end 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 objects = module_app_class.order_by(:view_count, :desc).limit(10) 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 sorted_objects = a.sort {|a,b| b[1]<=>a[1]} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fc93c29a..8f651392 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -181,7 +181,7 @@ module ApplicationHelper end def display_visitors(options={}) - Impression.where(options).distinct(:session_hash).count + Impression.where(options).and(:referrer.ne => nil).distinct(:session_hash).count end def display_visitors_today diff --git a/config/mongoid.yml b/config/mongoid.yml index 16405831..ecc3648d 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -8,7 +8,7 @@ defaults: &defaults development: <<: *defaults - database: prototype_r4_ldap0229 + database: bob test: <<: *defaults @@ -22,4 +22,4 @@ production: # password: <%= ENV['MONGOID_PASSWORD'] %> # database: <%= ENV['MONGOID_DATABASE'] %> <<: *defaults - database: prototype_r4_ldap0229 + database: prototype_r4_development diff --git a/vendor/impressionist/lib/impressionist/models/mongoid/impression.rb b/vendor/impressionist/lib/impressionist/models/mongoid/impression.rb index 5edc2edd..9a2d958c 100644 --- a/vendor/impressionist/lib/impressionist/models/mongoid/impression.rb +++ b/vendor/impressionist/lib/impressionist/models/mongoid/impression.rb @@ -27,11 +27,13 @@ class Impression private 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 - resouce = impressionable_class.find(self.impressionable_id) - resouce.try(:update_impressionist_counter_cache) + if impressionable_class.impressionist_counter_cache_options + resouce = impressionable_class.find(self.impressionable_id) + resouce.try(:update_impressionist_counter_cache) + end end end end