[replication] Try master if replica is missing status.

This commit is contained in:
Fosco Marotto 2021-01-23 14:43:01 -05:00
parent 41790e4894
commit 588894e2c2
4 changed files with 35 additions and 4 deletions

View File

@ -34,6 +34,15 @@ class Api::V1::Statuses::FavouritesController < Api::BaseController
end end
def requested_status def requested_status
Status.find(params[:status_id]) rs = nil
begin
rs = Status.find(params[:status_id])
rescue ActiveRecord::RecordNotFound
Status.connection.stick_to_master!
rs = Status.find(params[:status_id])
end
return rs unless rs.nil?
raise ActiveRecord::RecordNotFound
end end
end end

View File

@ -31,7 +31,15 @@ class Api::V1::Statuses::ReblogsController < Api::BaseController
private private
def status_for_reblog def status_for_reblog
Status.find params[:status_id] rs = nil
begin
rs = Status.find(params[:status_id])
rescue ActiveRecord::RecordNotFound
Status.connection.stick_to_master!
rs = Status.find(params[:status_id])
end
return rs unless rs.nil?
raise ActiveRecord::RecordNotFound
end end
def status_for_destroy def status_for_destroy

View File

@ -10,7 +10,14 @@ class FavouriteService < BaseService
def call(account, status) def call(account, status)
authorize_with account, status, :favourite? authorize_with account, status, :favourite?
favourite = Favourite.find_by(account: account, status: status) favourite = nil
begin
favourite = Favourite.find_by(account: account, status: status)
rescue ActiveRecord::RecordNotFound
Favourite.connection.stick_to_master!
favourite = Favourite.find_by(account: account, status: status)
end
# favourite = Favourite.find_by(account: account, status: status)
return favourite unless favourite.nil? return favourite unless favourite.nil?

View File

@ -13,7 +13,14 @@ class ReblogService < BaseService
authorize_with account, reblogged_status, :reblog? authorize_with account, reblogged_status, :reblog?
reblog = account.statuses.find_by(reblog: reblogged_status) reblog = nil
begin
reblog = account.statuses.find_by(reblog: reblogged_status)
rescue ActiveRecord::RecordNotFound
account.statuses.connection.stick_to_master!
reblog = account.statuses.find_by(reblog: reblogged_status)
end
#reblog = account.statuses.find_by(reblog: reblogged_status)
return reblog unless reblog.nil? return reblog unless reblog.nil?