mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Handle PG readonly mode in Auth::DefaultCurrentUserProvider
.
Avoid writing to the DB when PG is in readonly mode.
This commit is contained in:
@ -290,7 +290,7 @@ class Auth::DefaultCurrentUserProvider
|
||||
end
|
||||
|
||||
def should_update_last_seen?
|
||||
return false if Discourse.pg_readonly_mode?
|
||||
return false unless can_write?
|
||||
|
||||
api = !!(@env[API_KEY_ENV]) || !!(@env[USER_API_KEY_ENV])
|
||||
|
||||
@ -309,17 +309,19 @@ class Auth::DefaultCurrentUserProvider
|
||||
raise Discourse::InvalidAccess
|
||||
end
|
||||
|
||||
api_key.update_columns(last_used_at: Time.zone.now)
|
||||
if can_write?
|
||||
api_key.update_columns(last_used_at: Time.zone.now)
|
||||
|
||||
if client_id.present? && client_id != api_key.client_id
|
||||
if client_id.present? && client_id != api_key.client_id
|
||||
|
||||
# invalidate old dupe api key for client if needed
|
||||
UserApiKey
|
||||
.where(client_id: client_id, user_id: api_key.user_id)
|
||||
.where('id <> ?', api_key.id)
|
||||
.destroy_all
|
||||
# invalidate old dupe api key for client if needed
|
||||
UserApiKey
|
||||
.where(client_id: client_id, user_id: api_key.user_id)
|
||||
.where('id <> ?', api_key.id)
|
||||
.destroy_all
|
||||
|
||||
api_key.update_columns(client_id: client_id)
|
||||
api_key.update_columns(client_id: client_id)
|
||||
end
|
||||
end
|
||||
|
||||
api_key.user
|
||||
@ -347,7 +349,7 @@ class Auth::DefaultCurrentUserProvider
|
||||
SingleSignOnRecord.find_by(external_id: external_id.to_s).try(:user)
|
||||
end
|
||||
|
||||
if user
|
||||
if user && can_write?
|
||||
api_key.update_columns(last_used_at: Time.zone.now)
|
||||
end
|
||||
|
||||
@ -389,4 +391,8 @@ class Auth::DefaultCurrentUserProvider
|
||||
).performed!
|
||||
end
|
||||
|
||||
def can_write?
|
||||
@can_write ||= !Discourse.pg_readonly_mode?
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user