From 588894e2c25cb37c78e3b40785221d86ff41644e Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 14:43:01 -0500 Subject: [PATCH 1/9] [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? From 8d09044ee47ba98a8b065650c9326a4905c2c1d9 Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 16:18:15 -0500 Subject: [PATCH 2/9] [doorkeeper] Attempt to fix oauth connect issues. --- app/controllers/api/base_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index f6e85528..283d8c37 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -94,6 +94,7 @@ class Api::BaseController < ApplicationController end def authorize_if_got_token!(*scopes) + Doorkeeper::AccessToken.connection.stick_to_master! doorkeeper_authorize!(*scopes) if doorkeeper_token end From 63ad3a1590268e0b424c5f84639889d0032698d0 Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 16:33:48 -0500 Subject: [PATCH 3/9] [doorkeeper] Attempt to fix oauth connect issues. --- app/controllers/api/base_controller.rb | 1 - config/routes.rb | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 283d8c37..f6e85528 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -94,7 +94,6 @@ class Api::BaseController < ApplicationController end def authorize_if_got_token!(*scopes) - Doorkeeper::AccessToken.connection.stick_to_master! doorkeeper_authorize!(*scopes) if doorkeeper_token end diff --git a/config/routes.rb b/config/routes.rb index 1e913d40..44a8163f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,9 @@ Rails.application.routes.draw do mount PgHero::Engine, at: 'pghero', as: :pghero end + Doorkeeper::AccessToken.connection.stick_to_master! + Doorkeeper::AccessGrant.connection.stick_to_master! + use_doorkeeper do controllers authorizations: 'oauth/authorizations', authorized_applications: 'oauth/authorized_applications', @@ -225,9 +228,9 @@ Rails.application.routes.draw do end namespace :chat_conversation_accounts do - # + # end - + resources :chat_conversation_accounts, only: :show do member do post :messenger_block_relationships @@ -365,7 +368,7 @@ Rails.application.routes.draw do resource :removed_accounts, only: [:show, :create, :destroy], controller: 'groups/removed_accounts' resource :password, only: [:create], controller: 'groups/password' resource :join_requests, only: [:show], controller: 'groups/requests' - + post '/join_requests/respond', to: 'groups/requests#respond_to_request' resource :pin, only: [:show, :create], controller: 'groups/pins' From 645def5f96aad25c67d0ffc49e6c4f72a0d9fdc3 Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 18:21:31 -0500 Subject: [PATCH 4/9] SessionActivation and groups query change --- app/lib/sorting_query_builder.rb | 2 +- config/routes.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/lib/sorting_query_builder.rb b/app/lib/sorting_query_builder.rb index 3d8fd76e..d70c78db 100644 --- a/app/lib/sorting_query_builder.rb +++ b/app/lib/sorting_query_builder.rb @@ -8,7 +8,7 @@ class SortingQueryBuilder < BaseService min_reblogs = 2 min_replies = 1 date_limit = 5.years.ago - pure_limit = "NOW() - INTERVAL '14 days'" + pure_limit = "NOW() - INTERVAL '3 days'" max_page = 8 case sort_type diff --git a/config/routes.rb b/config/routes.rb index 44a8163f..905be549 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,7 @@ Rails.application.routes.draw do Doorkeeper::AccessToken.connection.stick_to_master! Doorkeeper::AccessGrant.connection.stick_to_master! + SessionActivation.connection.stick_to_master! use_doorkeeper do controllers authorizations: 'oauth/authorizations', From acea03da3879a949ada00eefcfa287d0397d7fda Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 20:31:27 -0500 Subject: [PATCH 5/9] Disable mute phrases on the home timeline --- app/models/home_feed.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/home_feed.rb b/app/models/home_feed.rb index b5a7bc75..73d5c461 100644 --- a/app/models/home_feed.rb +++ b/app/models/home_feed.rb @@ -45,12 +45,13 @@ class HomeFeed < Feed ) st left join statuses rb on st.reblog_of_id = rb.id - left join custom_filters cf - on cf.account_id = #{@id} and ( - st.text like '%' || cf.phrase || '%' - or rb.text like '%' || cf.phrase || '%') - where cf.id is null or st.account_id = #{@id} " + # left join custom_filters cf + # on cf.account_id = #{@id} and ( + # st.text like '%' || cf.phrase || '%' + # or rb.text like '%' || cf.phrase || '%') + # where cf.id is null or st.account_id = #{@id} + #" # .reject { |status| FeedManager.instance.filter?(:home, status, @account.id) } # Status.as_home_timeline(@account) # .paginate_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id) From 2e9562e2fc3eac1d79d562ba74efa86b732cbbcb Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 21:36:17 -0500 Subject: [PATCH 6/9] [home] Reduce following fanout to recent users --- app/models/home_feed.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/home_feed.rb b/app/models/home_feed.rb index 73d5c461..84f95641 100644 --- a/app/models/home_feed.rb +++ b/app/models/home_feed.rb @@ -33,7 +33,13 @@ class HomeFeed < Feed and s.reply is false and ( s.account_id = #{@id} - or s.account_id in (select target_account_id from follows where account_id = #{@id}) + or s.account_id in ( + select ff.target_account_id + from follows ff + join accounts af + on ff.target_account_id = af.id + and af.updated_at > NOW() - INTERVAL '7 days' + where ff.account_id = #{@id}) ) and s.account_id not in (select target_account_id from mutes where account_id = #{@id}) and (reblog.id is null or reblog.account_id not in (select target_account_id from mutes where account_id = #{@id})) From 59b1752797d3122805cc6ddb95ff4793b9da801d Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 21:38:17 -0500 Subject: [PATCH 7/9] [groups collection] disable custom phrase muting temporarily --- app/lib/sorting_query_builder.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/lib/sorting_query_builder.rb b/app/lib/sorting_query_builder.rb index d70c78db..2cb50f6e 100644 --- a/app/lib/sorting_query_builder.rb +++ b/app/lib/sorting_query_builder.rb @@ -80,11 +80,12 @@ class SortingQueryBuilder < BaseService query += " ) q - left join custom_filters cf - on cf.account_id = #{account_id} - and q.text like '%' || cf.phrase || '%' - where cf.id is null " + #left join custom_filters cf + # on cf.account_id = #{account_id} + # and q.text like '%' || cf.phrase || '%' + #where cf.id is null + #" return Status.find_by_sql query end From d39664b827c25b83d30a288163aa18b123c8e5c2 Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 23:23:55 -0500 Subject: [PATCH 8/9] [home] refactor the home timeline query --- app/models/home_feed.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/models/home_feed.rb b/app/models/home_feed.rb index 84f95641..a84ed0f9 100644 --- a/app/models/home_feed.rb +++ b/app/models/home_feed.rb @@ -28,18 +28,15 @@ class HomeFeed < Feed from statuses s left join statuses reblog on s.reblog_of_id = reblog.id + left join follows f + on s.account_id = f.target_account_id + and f.account_id = #{@id} where s.created_at > NOW() - INTERVAL '7 days' and s.reply is false and ( s.account_id = #{@id} - or s.account_id in ( - select ff.target_account_id - from follows ff - join accounts af - on ff.target_account_id = af.id - and af.updated_at > NOW() - INTERVAL '7 days' - where ff.account_id = #{@id}) + or f.id is not null ) and s.account_id not in (select target_account_id from mutes where account_id = #{@id}) and (reblog.id is null or reblog.account_id not in (select target_account_id from mutes where account_id = #{@id})) @@ -58,8 +55,5 @@ class HomeFeed < Feed # or rb.text like '%' || cf.phrase || '%') # where cf.id is null or st.account_id = #{@id} #" - # .reject { |status| FeedManager.instance.filter?(:home, status, @account.id) } - # Status.as_home_timeline(@account) - # .paginate_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id) end end From d8230aeaa001e19bd10f113c33710ab2fb1a4819 Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Sat, 23 Jan 2021 23:35:52 -0500 Subject: [PATCH 9/9] Revert "[home] refactor the home timeline query" This reverts commit d39664b827c25b83d30a288163aa18b123c8e5c2. --- app/models/home_feed.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/home_feed.rb b/app/models/home_feed.rb index a84ed0f9..84f95641 100644 --- a/app/models/home_feed.rb +++ b/app/models/home_feed.rb @@ -28,15 +28,18 @@ class HomeFeed < Feed from statuses s left join statuses reblog on s.reblog_of_id = reblog.id - left join follows f - on s.account_id = f.target_account_id - and f.account_id = #{@id} where s.created_at > NOW() - INTERVAL '7 days' and s.reply is false and ( s.account_id = #{@id} - or f.id is not null + or s.account_id in ( + select ff.target_account_id + from follows ff + join accounts af + on ff.target_account_id = af.id + and af.updated_at > NOW() - INTERVAL '7 days' + where ff.account_id = #{@id}) ) and s.account_id not in (select target_account_id from mutes where account_id = #{@id}) and (reblog.id is null or reblog.account_id not in (select target_account_id from mutes where account_id = #{@id})) @@ -55,5 +58,8 @@ class HomeFeed < Feed # or rb.text like '%' || cf.phrase || '%') # where cf.id is null or st.account_id = #{@id} #" + # .reject { |status| FeedManager.instance.filter?(:home, status, @account.id) } + # Status.as_home_timeline(@account) + # .paginate_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id) end end