fix delay impressionist for tags and pages
This commit is contained in:
		
							parent
							
								
									f025c98ffa
								
							
						
					
					
						commit
						8043573370
					
				|  | @ -9,7 +9,8 @@ module ApplicationHelper | ||||||
| 
 | 
 | ||||||
|   def delayed_impressionist(item) |   def delayed_impressionist(item) | ||||||
|     user_id = current_user.nil? ? nil : current_user.id |     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 |   end | ||||||
| 
 | 
 | ||||||
|   def check_user_role_enable(attribute_fields) |   def check_user_role_enable(attribute_fields) | ||||||
|  |  | ||||||
|  | @ -1,16 +1,18 @@ | ||||||
| class DashboardCounter < Resque::Plugins::RestrictionJob | class DashboardCounter < Resque::Plugins::RestrictionJob | ||||||
|   include OrbitApp::Module::VisitorCounter |   extend OrbitApp::Module::VisitorCounterEval | ||||||
| 
 | 
 | ||||||
|   @queue = :high |   @queue = :high | ||||||
| 
 | 
 | ||||||
|   def self.perform(*args) |   def self.perform(*args) | ||||||
|     site = Site.first |     site = Site.first | ||||||
|     obj = new(*args) |     obj = new(*args) | ||||||
|     site.dashboard_counter[:visitors_this_week] = obj.display_visitors_this_week  |     site.visitor_counters[:total] = display_visitors | ||||||
|     site.dashboard_counter[:visitors_this_month] = obj.display_visitors_this_month  |     site.visitor_counters[:today] = display_visitors_today  | ||||||
|     site.dashboard_counter[:visitors_this_year] = obj.display_visitors_this_year |     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 |     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. |     #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. |     #and the site model will need a field call dashboard_counter to complete this job. | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ class DelayedImpressionist | ||||||
|     @request= DelayImpressionistRequest.new |     @request= DelayImpressionistRequest.new | ||||||
|     @request.restore(arg["request"]) |     @request.restore(arg["request"]) | ||||||
|     request = @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) |     # 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 = 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 |     new_impression.save | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ class UpdateTagCloud | ||||||
| 
 | 
 | ||||||
|   def self.perform() |   def self.perform() | ||||||
|     Tag.all.each do |tag| |     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 |     end | ||||||
|     OrbitLogger.info "UpdateTagCloud Done" |     OrbitLogger.info "UpdateTagCloud Done" | ||||||
|   end |   end | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ class Site | ||||||
|   field :title_always_on, :type => Boolean, :default => false |   field :title_always_on, :type => Boolean, :default => false | ||||||
|   field :dashbroad_allow_visitor, :type => Boolean, :default => false |   field :dashbroad_allow_visitor, :type => Boolean, :default => false | ||||||
|   field :mail_settings, :type => Hash |   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 :disk_space, :type => String | ||||||
|   field :system_package_info, :type => Hash,:default=>{} |   field :system_package_info, :type => Hash,:default=>{} | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ class Tag | ||||||
|   include Mongoid::Timestamps |   include Mongoid::Timestamps | ||||||
|   include Impressionist::Impressionable |   include Impressionist::Impressionable | ||||||
|    |    | ||||||
|   is_impressionable :counter_cache => { :column_name => :view_count } |   is_impressionable #:counter_cache => { :column_name => :view_count } | ||||||
|    |    | ||||||
|   field :name, localize: true |   field :name, localize: true | ||||||
|   field :view_count, :type => Integer, :default => 0 |   field :view_count, :type => Integer, :default => 0 | ||||||
|  |  | ||||||
|  | @ -1,3 +1,9 @@ | ||||||
|  | dashboard_counter_cache: | ||||||
|  |   cron: 0 * * * * * | ||||||
|  |   class: DashboardCounter | ||||||
|  |   args: | ||||||
|  |   description: DashboardCounterCache | ||||||
|  | 
 | ||||||
| update_tag_cloud: | update_tag_cloud: | ||||||
|   cron: 0 0 [0,12] * * * |   cron: 0 0 [0,12] * * * | ||||||
|   class: UpdateTagCloud |   class: UpdateTagCloud | ||||||
|  |  | ||||||
|  | @ -4,23 +4,23 @@ module OrbitApp | ||||||
|         Version = "0.1" |         Version = "0.1" | ||||||
| 
 | 
 | ||||||
|         def display_visitors(options={}) |         def display_visitors(options={}) | ||||||
|           impressions = Impression.where(options).and(:referrer.ne => nil).distinct(:session_hash).count |           Site.first.visitor_counters["total"] | ||||||
|         end |         end | ||||||
| 
 | 
 | ||||||
|         def display_visitors_today |         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 |         end | ||||||
| 
 | 
 | ||||||
|         def display_visitors_this_week |         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 |         end | ||||||
| 
 | 
 | ||||||
|         def display_visitors_this_month |         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 |         end | ||||||
| 
 | 
 | ||||||
|         def display_visitors_this_year |         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 | ||||||
| 
 | 
 | ||||||
|     end # of VisitorCounter |     end # of VisitorCounter | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
|  | @ -320,6 +320,9 @@ namespace :migrate do | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|  | 
 | ||||||
|  |   task :clear_news_tags => :environment do | ||||||
|  |     `mongo #{Mongoid.config.database.name} --eval "db.tags.remove({_type: {$ne: 'Tag'}})"` | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -26,6 +26,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def index |   def index | ||||||
|  | 
 | ||||||
|     @item = Page.find(params[:page_id]) rescue nil |     @item = Page.find(params[:page_id]) rescue nil | ||||||
|     if @item |     if @item | ||||||
|       if @item.frontend_data_count |       if @item.frontend_data_count | ||||||
|  | @ -60,7 +61,10 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController | ||||||
|       else |       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) |         @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 |       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 | ||||||
| 
 | 
 | ||||||
|   end |   end | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue