From e5826777b6c06a32b97388657beaca1e5eccb421 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 30 Jul 2025 18:28:26 +0200 Subject: [PATCH] Fix friends-of-friends recommendations suggesting already-requested accounts (#35604) --- .../account_suggestions/friends_of_friends_source.rb | 1 + .../friends_of_friends_source_spec.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/account_suggestions/friends_of_friends_source.rb b/app/models/account_suggestions/friends_of_friends_source.rb index 707c6ccaec2..d4accd2cea6 100644 --- a/app/models/account_suggestions/friends_of_friends_source.rb +++ b/app/models/account_suggestions/friends_of_friends_source.rb @@ -26,6 +26,7 @@ class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source AND NOT EXISTS (SELECT 1 FROM mutes m WHERE m.target_account_id = follows.target_account_id AND m.account_id = :id) AND (accounts.domain IS NULL OR NOT EXISTS (SELECT 1 FROM account_domain_blocks b WHERE b.account_id = :id AND b.domain = accounts.domain)) AND NOT EXISTS (SELECT 1 FROM follows f WHERE f.target_account_id = follows.target_account_id AND f.account_id = :id) + AND NOT EXISTS (SELECT 1 FROM follow_requests f WHERE f.target_account_id = follows.target_account_id AND f.account_id = :id) AND follows.target_account_id <> :id AND accounts.discoverable AND accounts.suspended_at IS NULL diff --git a/spec/models/account_suggestions/friends_of_friends_source_spec.rb b/spec/models/account_suggestions/friends_of_friends_source_spec.rb index 9daaa233bfd..af1e6e98896 100644 --- a/spec/models/account_suggestions/friends_of_friends_source_spec.rb +++ b/spec/models/account_suggestions/friends_of_friends_source_spec.rb @@ -16,10 +16,12 @@ RSpec.describe AccountSuggestions::FriendsOfFriendsSource do let!(:jerk) { Fabricate(:account, discoverable: true, hide_collections: false) } let!(:larry) { Fabricate(:account, discoverable: true, hide_collections: false) } let!(:morty) { Fabricate(:account, discoverable: true, hide_collections: false, memorial: true) } + let!(:joyce) { Fabricate(:account, discoverable: true, hide_collections: false) } context 'with follows and blocks' do before do bob.block!(jerk) + bob.request_follow!(joyce) FollowRecommendationMute.create!(account: bob, target_account: neil) # bob follows eugen, alice and larry @@ -28,8 +30,8 @@ RSpec.describe AccountSuggestions::FriendsOfFriendsSource do # alice follows eve and mallory [john, mallory].each { |account| alice.follow!(account) } - # eugen follows eve, john, jerk, larry, neil and morty - [eve, mallory, jerk, larry, neil, morty].each { |account| eugen.follow!(account) } + # eugen follows eve, john, jerk, larry, neil, morty and joyce + [eve, mallory, jerk, larry, neil, morty, joyce].each { |account| eugen.follow!(account) } end it 'returns eligible accounts', :aggregate_failures do @@ -55,6 +57,9 @@ RSpec.describe AccountSuggestions::FriendsOfFriendsSource do # morty is not included because his account is in memoriam expect(results).to_not include([morty.id, :friends_of_friends]) + + # joyce is not included because there is already a pending follow request + expect(results).to_not include([joyce.id, :friends_of_friends]) end end