PERF: defer last_ip_address and last_seen updates

This commit is contained in:
Sam 2014-03-03 15:16:10 +11:00
parent 172e517b31
commit ceb80611d6
2 changed files with 17 additions and 2 deletions

@ -0,0 +1,12 @@
module Jobs
# Asynchronously send an email to a user
class UpdateUserInfo < Jobs::Base
def execute(args)
user = User.where(id: args[:user_id]).first
user.update_last_seen!
user.update_ip_address!(args[:ip_address])
end
end
end

@ -12,6 +12,7 @@ class Auth::DefaultCurrentUserProvider
@request = Rack::Request.new(env)
end
# our current user, return nil if none is found
def current_user
return @env[CURRENT_USER_KEY] if @env.key?(CURRENT_USER_KEY)
@ -31,8 +32,10 @@ class Auth::DefaultCurrentUserProvider
end
if current_user
current_user.update_last_seen!
current_user.update_ip_address!(request.ip)
Jobs.enqueue(:update_user_info,
user_id: current_user.id,
ip: request.ip)
end
# possible we have an api call, impersonate