fix delay impressionist for tags and pages

This commit is contained in:
Matt K. Fu 2013-07-19 16:59:08 +08:00
parent f025c98ffa
commit 8043573370
11 changed files with 59 additions and 15 deletions

View File

@ -9,7 +9,8 @@ module ApplicationHelper
def delayed_impressionist(item)
user_id = current_user.nil? ? nil : current_user.id
Resque.enqueue(DelayedImpressionist,:request=>DelayImpressionistRequest.new(request),:obj=>item,:class=>item.class.to_s,:controller_name=>controller_name,:action_name=>action_name,:user=>user_id)
request = DelayImpressionistRequest.new(request)
Resque.enqueue(DelayedImpressionist,:request=>request,:obj=>item,:class=>item.class.to_s,:controller_name=>controller_name,:action_name=>action_name,:user=>user_id)
end
def check_user_role_enable(attribute_fields)

View File

@ -1,16 +1,18 @@
class DashboardCounter < Resque::Plugins::RestrictionJob
include OrbitApp::Module::VisitorCounter
extend OrbitApp::Module::VisitorCounterEval
@queue = :high
def self.perform(*args)
site = Site.first
obj = new(*args)
site.dashboard_counter[:visitors_this_week] = obj.display_visitors_this_week
site.dashboard_counter[:visitors_this_month] = obj.display_visitors_this_month
site.dashboard_counter[:visitors_this_year] = obj.display_visitors_this_year
site.visitor_counters[:total] = display_visitors
site.visitor_counters[:today] = display_visitors_today
site.visitor_counters[:this_week] = display_visitors_this_week
site.visitor_counters[:this_month] = display_visitors_this_month
site.visitor_counters[:this_year] = display_visitors_this_year
site.save
OrbitLogger.info "DashboardCounter done #{site.dashboard_counter.to_s}"
OrbitLogger.info "DashboardCounter done #{site.visitor_counters.to_s}"
#Notice this is mainly used at user dashbroad. however the code there is currentlly using realtime evaluation.
#and the site model will need a field call dashboard_counter to complete this job.

View File

@ -18,7 +18,7 @@ class DelayedImpressionist
@request= DelayImpressionistRequest.new
@request.restore(arg["request"])
request = @request
obj = eval(arg["class"]).find arg["obj"]["_id"]
obj = eval("#{arg["class"]}.find '#{arg['obj']['_id']}'")
# imp = new(@request,arg["controller_name"],arg["action_name"],arg["user"],obj)
new_impression = obj.impressions.build(:user_id=>arg["user"],:controller_name=>arg["controller_name"],:action_name=>arg["action_name"],:ip_address=>@request.remote_ip,:referrer=>@request.referer)
new_impression.save

View File

@ -3,7 +3,7 @@ class UpdateTagCloud
def self.perform()
Tag.all.each do |tag|
tag.update_attribute(:cloud_view_count, tag.impressionist_count(:created_at.gte => 14.days.ago, :created_at.lte => Time.now))
tag.update_attribute(:cloud_view_count, tag.get_impressionist)
end
OrbitLogger.info "UpdateTagCloud Done"
end

View File

@ -18,6 +18,7 @@ class Site
field :title_always_on, :type => Boolean, :default => false
field :dashbroad_allow_visitor, :type => Boolean, :default => false
field :mail_settings, :type => Hash
field :visitor_counters,:type=> Hash,:default=>{:total=>0,:today=>0,:this_week=>0,:this_month=>0,:this_year=>0}
field :disk_space, :type => String
field :system_package_info, :type => Hash,:default=>{}

View File

@ -8,7 +8,7 @@ class Tag
include Mongoid::Timestamps
include Impressionist::Impressionable
is_impressionable :counter_cache => { :column_name => :view_count }
is_impressionable #:counter_cache => { :column_name => :view_count }
field :name, localize: true
field :view_count, :type => Integer, :default => 0

View File

@ -1,3 +1,9 @@
dashboard_counter_cache:
cron: 0 * * * * *
class: DashboardCounter
args:
description: DashboardCounterCache
update_tag_cloud:
cron: 0 0 [0,12] * * *
class: UpdateTagCloud

View File

@ -4,23 +4,23 @@ module OrbitApp
Version = "0.1"
def display_visitors(options={})
impressions = Impression.where(options).and(:referrer.ne => nil).distinct(:session_hash).count
Site.first.visitor_counters["total"]
end
def display_visitors_today
display_visitors(created_at: {'$gte' => Date.today.beginning_of_day, '$lte' => Date.today.end_of_day})
Site.first.visitor_counters["today"]
end
def display_visitors_this_week
display_visitors(created_at: {'$gte' => Date.today.beginning_of_week, '$lte' => Date.today.end_of_week})
Site.first.visitor_counters["this_week"]
end
def display_visitors_this_month
display_visitors(created_at: {'$gte' => Date.today.beginning_of_month, '$lte' => Date.today.end_of_month})
Site.first.visitor_counters["this_month"]
end
def display_visitors_this_year
display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year})
Site.first.visitor_counters["this_year"]
end
end # of VisitorCounter

View File

@ -0,0 +1,27 @@
module OrbitApp
module Module
module VisitorCounterEval
Version = "0.1"
def display_visitors(options={})
impressions = Impression.where(options).and(:referrer.ne => nil).distinct(:session_hash).count
end
def display_visitors_today
display_visitors(created_at: {'$gte' => Date.today.beginning_of_day, '$lte' => Date.today.end_of_day})
end
def display_visitors_this_week
display_visitors(created_at: {'$gte' => Date.today.beginning_of_week, '$lte' => Date.today.end_of_week})
end
def display_visitors_this_month
display_visitors(created_at: {'$gte' => Date.today.beginning_of_month, '$lte' => Date.today.end_of_month})
end
def display_visitors_this_year
display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year})
end
end # end of VisitorCounterEval
end # of Module
end # of OrbitApp

View File

@ -320,6 +320,9 @@ namespace :migrate do
end
end
end
task :clear_news_tags => :environment do
`mongo #{Mongoid.config.database.name} --eval "db.tags.remove({_type: {$ne: 'Tag'}})"`
end
end

View File

@ -26,6 +26,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
end
def index
@item = Page.find(params[:page_id]) rescue nil
if @item
if @item.frontend_data_count
@ -60,7 +61,10 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
else
@bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
end
delayed_impressionist(@tag) if @tag
if params["tag_id"]
params["tag_id"].each do |tag_id|
delayed_impressionist(Tag.find tag_id) rescue
end
end
end