Bundle of corrections and one doorkeeper writing role change

This commit is contained in:
Fosco Marotto 2021-02-09 22:32:24 -05:00
parent 382fd31ec7
commit 729c00a5a9
12 changed files with 18 additions and 45 deletions

View File

@ -65,11 +65,9 @@ class Api::BaseController < ApplicationController
def current_resource_owner
if doorkeeper_token
@current_user ||= Rails.cache.fetch("dk:user:#{doorkeeper_token.resource_owner_id}", expires_in: 25.hours) do
u = nil
ActiveRecord::Base.connected_to(role: :writing) do
u = User.find(doorkeeper_token.resource_owner_id)
User.find(doorkeeper_token.resource_owner_id)
end
u
end
end
return @current_user

View File

@ -28,11 +28,9 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
end
def load_statuses
cas = nil
ActiveRecord::Base.connected_to(role: :reading) do
cas = cached_account_statuses
cached_account_statuses
end
cas
end
def cached_account_statuses

View File

@ -17,11 +17,9 @@ class Api::V1::BookmarkCollections::BookmarksController < Api::BaseController
private
def load_statuses
cb = nil
ActiveRecord::Base.connected_to(role: :reading) do
cb = cached_bookmarks
cached_bookmarks
end
cb
end
def cached_bookmarks
@ -29,7 +27,7 @@ class Api::V1::BookmarkCollections::BookmarksController < Api::BaseController
Status.reorder(nil).joins(:status_bookmarks).merge(results),
Status
)
`` end
end
def results
@_results ||= account_bookmarks.paginate_by_id(

View File

@ -39,11 +39,9 @@ class Api::V1::Timelines::ExploreController < Api::BaseController
end
def cached_explore_statuses
es = nil
ActiveRecord::Base.connected_to(role: :reading) do
es = cache_collection explore_statuses, Status
cache_collection explore_statuses, Status
end
es
end
def explore_statuses

View File

@ -56,11 +56,9 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController
end
def cached_group_collection_statuses
gcs = nil
ActiveRecord::Base.connected_to(role: :reading) do
gcs = cache_collection group_collection_statuses, Status
cache_collection group_collection_statuses, Status
end
gcs
end
def group_collection_statuses

View File

@ -46,11 +46,9 @@ class Api::V1::Timelines::GroupController < Api::BaseController
end
def cached_group_statuses
gs = nil
ActiveRecord::Base.connected_to(role: :reading) do
gs = cache_collection group_statuses, Status
cache_collection group_statuses, Status
end
gs
end
def group_statuses

View File

@ -16,11 +16,9 @@ class Api::V1::Timelines::ProController < Api::BaseController
end
def cached_pro_statuses
ps = nil
ActiveRecord::Base.connected_to(role: :reading) do
ps = cache_collection pro_statuses, Status
cache_collection pro_statuses, Status
end
ps
end
def pro_statuses

View File

@ -90,11 +90,9 @@ class ApplicationController < ActionController::Base
def current_session
return nil if cookies.signed['_session_id'].nil?
@current_session ||= Rails.cache.fetch("dk:sess:#{cookies.signed['_session_id']}", expires_in: 25.hours) do
sa = nil
ActiveRecord::Base.connected_to(role: :writing) do
sa = SessionActivation.find_by(session_id: cookies.signed['_session_id'])
SessionActivation.find_by(session_id: cookies.signed['_session_id'])
end
sa
end
end

View File

@ -155,16 +155,13 @@ class User < ApplicationRecord
end
def update_tracked_fields!(request)
ru = nil
ActiveRecord::Base.connected_to(role: :writing) do
super
ru = prepare_returning_user!
prepare_returning_user!
end
ru
end
def update_sign_in!(request, new_sign_in: false)
ru = nil
ActiveRecord::Base.connected_to(role: :writing) do
old_current, new_current = current_sign_in_at, Time.now.utc
self.last_sign_in_at = old_current || new_current
@ -180,9 +177,8 @@ class User < ApplicationRecord
end
save(validate: false) unless new_record?
ru = prepare_returning_user!
prepare_returning_user!
end
ru
end
def disable_two_factor!

View File

@ -10,16 +10,7 @@ class FavouriteService < BaseService
def call(account, status)
authorize_with account, status, :favourite?
favourite = nil
begin
favourite = Favourite.find_by(account: account, status: status)
rescue ActiveRecord::RecordNotFound
favourite = Favourite.find_by(account: account, status: status)
end
return favourite unless favourite.nil?
favourite = Favourite.create!(account: account, status: status)
favourite = Favourite.find_or_create_by!(account: account, status: status)
create_notification(favourite)
bump_potential_friendship(account, status)

View File

@ -20,7 +20,7 @@ development:
encoding: unicode
slave2:
adapter: postgresql
url: <%= ENV['DB_SLAVE1_URL'] %>
url: <%= ENV['DB_SLAVE2_URL'] %>
pool: <%= ENV['DB_POOL'] %>
timeout: 5000
encoding: unicode
@ -69,4 +69,4 @@ production:
pool: <%= ENV['DB_POOL'] %>
timeout: 5000
encoding: unicode

View File

@ -8,8 +8,10 @@ Doorkeeper.configure do
end
resource_owner_from_credentials do |_routes|
user = User.find_by(email: request.params[:username])
user if !user&.otp_required_for_login? && user&.valid_password?(request.params[:password])
ActiveRecord::Base.connected_to(role: :writing) do
user = User.find_by(email: request.params[:username])
user if !user&.otp_required_for_login? && user&.valid_password?(request.params[:password])
end
end
# If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.