Avoid redundant OAuth queries when not signed in
If you aren't signed in, you don't have an auth token. When you don't have an auth token, React was sending the headers "Authorization: Bearer null" This caused 5 Doorkeeper token lookups using WHERE "oauth_access_tokens"."token" = 'null' on the Explore page (the root of the app when not signed in).
This commit is contained in:
@@ -15,11 +15,6 @@ class AccountModerationNote < ApplicationRecord
|
||||
belongs_to :account
|
||||
belongs_to :target_account, class_name: 'Account'
|
||||
|
||||
connects_to database: {
|
||||
writing: :master,
|
||||
reading: :master
|
||||
}
|
||||
|
||||
scope :latest, -> { reorder('created_at DESC') }
|
||||
|
||||
validates :content, presence: true, length: { maximum: 500 }
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
class AccountVerificationRequest < ApplicationRecord
|
||||
|
||||
connects_to database: {
|
||||
writing: :master,
|
||||
reading: :master
|
||||
writing: :primary,
|
||||
reading: :primary
|
||||
}
|
||||
|
||||
LIMIT = 4.megabytes
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
connects_to database: {
|
||||
writing: :master,
|
||||
writing: :primary,
|
||||
reading: :slave1
|
||||
}
|
||||
self.abstract_class = true
|
||||
|
||||
@@ -29,11 +29,6 @@ class Report < ApplicationRecord
|
||||
|
||||
validates :comment, length: { maximum: 1000 }
|
||||
|
||||
connects_to database: {
|
||||
writing: :master,
|
||||
reading: :master
|
||||
}
|
||||
|
||||
def local?
|
||||
false # Force uri_for to use uri attribute
|
||||
end
|
||||
|
||||
@@ -19,9 +19,4 @@ class ReportNote < ApplicationRecord
|
||||
|
||||
validates :content, presence: true, length: { maximum: 500 }
|
||||
|
||||
connects_to database: {
|
||||
writing: :master,
|
||||
reading: :master
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
@@ -23,11 +23,6 @@ class SessionActivation < ApplicationRecord
|
||||
to: :access_token,
|
||||
allow_nil: true
|
||||
|
||||
connects_to database: {
|
||||
writing: :master,
|
||||
reading: :master
|
||||
}
|
||||
|
||||
def detection
|
||||
@detection ||= Browser.new(user_agent)
|
||||
end
|
||||
@@ -45,7 +40,9 @@ class SessionActivation < ApplicationRecord
|
||||
|
||||
class << self
|
||||
def active?(id)
|
||||
id && where(session_id: id).exists?
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
id && where(session_id: id).exists?
|
||||
end
|
||||
end
|
||||
|
||||
def activate(**options)
|
||||
@@ -61,19 +58,16 @@ class SessionActivation < ApplicationRecord
|
||||
|
||||
def deactivate(id)
|
||||
return unless id
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
conn = ActiveRecord::Base.connection
|
||||
conn.exec_query "delete from session_activations where session_id = '#{id}'"
|
||||
end
|
||||
where(session_id: id).destroy_all
|
||||
end
|
||||
|
||||
def purge_old
|
||||
order('created_at desc').offset(Rails.configuration.x.max_session_activations).destroy_all
|
||||
end
|
||||
|
||||
def exclusive(id)
|
||||
where('session_id != ?', id).destroy_all
|
||||
end
|
||||
#def exclusive(id)
|
||||
# where('session_id != ?', id).destroy_all
|
||||
#end
|
||||
end
|
||||
|
||||
private
|
||||
@@ -93,6 +87,5 @@ class SessionActivation < ApplicationRecord
|
||||
expires_in: Doorkeeper.configuration.access_token_expires_in,
|
||||
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?)
|
||||
end
|
||||
self.access_token
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user