mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 03:45:33 +08:00
PERF: defer last_ip_address and last_seen updates
This commit is contained in:
parent
172e517b31
commit
ceb80611d6
12
app/jobs/regular/update_user_info.rb
Normal file
12
app/jobs/regular/update_user_info.rb
Normal file
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user