From 588894e2c25cb37c78e3b40785221d86ff41644e Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 14:43:01 -0500 Subject: [PATCH] [replication] Try master if replica is missing status. --- .../api/v1/statuses/favourites_controller.rb | 11 ++++++++++- app/controllers/api/v1/statuses/reblogs_controller.rb | 10 +++++++++- app/services/favourite_service.rb | 9 ++++++++- app/services/reblog_service.rb | 9 ++++++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/statuses/favourites_controller.rb b/app/controllers/api/v1/statuses/favourites_controller.rb index 96582d6d..52658901 100644 --- a/app/controllers/api/v1/statuses/favourites_controller.rb +++ b/app/controllers/api/v1/statuses/favourites_controller.rb @@ -34,6 +34,15 @@ class Api::V1::Statuses::FavouritesController < Api::BaseController end 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 diff --git a/app/controllers/api/v1/statuses/reblogs_controller.rb b/app/controllers/api/v1/statuses/reblogs_controller.rb index 9e17dfd9..a05ada84 100644 --- a/app/controllers/api/v1/statuses/reblogs_controller.rb +++ b/app/controllers/api/v1/statuses/reblogs_controller.rb @@ -31,7 +31,15 @@ class Api::V1::Statuses::ReblogsController < Api::BaseController private 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 def status_for_destroy diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb index c9928150..fbe0152e 100644 --- a/app/services/favourite_service.rb +++ b/app/services/favourite_service.rb @@ -10,7 +10,14 @@ class FavouriteService < BaseService def call(account, status) 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? diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb index 067c0b75..efe73f9f 100644 --- a/app/services/reblog_service.rb +++ b/app/services/reblog_service.rb @@ -13,7 +13,14 @@ class ReblogService < BaseService 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?