2013-07-18 04:03:18 +00:00
|
|
|
class DelayedImpressionist
|
|
|
|
def self.before_filter(*args)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
include ImpressionistController::InstanceMethods
|
|
|
|
@queue = :low
|
|
|
|
|
|
|
|
def initialize(request,controller_name,action_name,user,obj)
|
|
|
|
@controller_name = controller_name
|
|
|
|
@action_name = action_name
|
|
|
|
@user = User.find user unless user.nil?
|
|
|
|
@request = request
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.perform(*args)
|
|
|
|
arg = args[0]
|
|
|
|
@request= DelayImpressionistRequest.new
|
|
|
|
@request.restore(arg["request"])
|
|
|
|
request = @request
|
2013-07-19 08:59:08 +00:00
|
|
|
obj = eval("#{arg["class"]}.find '#{arg['obj']['_id']}'")
|
2013-07-18 04:03:18 +00:00
|
|
|
# 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
|
|
|
|
obj.update_attribute(:view_count,obj.impression_count)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def user
|
|
|
|
@user
|
|
|
|
end
|
|
|
|
|
|
|
|
def action_name
|
|
|
|
@action_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def controller_name
|
|
|
|
@controller_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def request
|
|
|
|
@request
|
|
|
|
end
|
|
|
|
|
2013-05-23 04:07:43 +00:00
|
|
|
end
|