mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-23 07:32:02 +01:00
Fix incorrect frequency value in FriendsOfFriendsSource
data (#29550)
This commit is contained in:
parent
24319836de
commit
216cea1e27
2 changed files with 32 additions and 10 deletions
|
@ -2,15 +2,19 @@
|
||||||
|
|
||||||
class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source
|
class AccountSuggestions::FriendsOfFriendsSource < AccountSuggestions::Source
|
||||||
def get(account, limit: DEFAULT_LIMIT)
|
def get(account, limit: DEFAULT_LIMIT)
|
||||||
|
source_query(account, limit: limit)
|
||||||
|
.map { |id, _frequency, _followers_count| [id, key] }
|
||||||
|
end
|
||||||
|
|
||||||
|
def source_query(account, limit: DEFAULT_LIMIT)
|
||||||
first_degree = account.following.where.not(hide_collections: true).select(:id).reorder(nil)
|
first_degree = account.following.where.not(hide_collections: true).select(:id).reorder(nil)
|
||||||
base_account_scope(account)
|
base_account_scope(account)
|
||||||
.joins(:account_stat)
|
.joins(:account_stat)
|
||||||
.where(id: Follow.where(account_id: first_degree).select(:target_account_id))
|
.joins(:passive_relationships).where(passive_relationships: { account_id: first_degree })
|
||||||
.group('accounts.id, account_stats.id')
|
.group('accounts.id, account_stats.id')
|
||||||
.reorder('frequency DESC, followers_count DESC')
|
.reorder(frequency: :desc, followers_count: :desc)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.pluck(Arel.sql('accounts.id, COUNT(*) AS frequency'))
|
.pluck(Arel.sql('accounts.id, COUNT(*) AS frequency, followers_count'))
|
||||||
.map { |id, _frequency| [id, key] }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -11,9 +11,9 @@ RSpec.describe AccountSuggestions::FriendsOfFriendsSource do
|
||||||
let!(:eve) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
let!(:eve) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||||
let!(:mallory) { Fabricate(:account, discoverable: false, hide_collections: false) }
|
let!(:mallory) { Fabricate(:account, discoverable: false, hide_collections: false) }
|
||||||
let!(:eugen) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
let!(:eugen) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||||
|
let!(:neil) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||||
let!(:john) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
let!(:john) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||||
let!(:jerk) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
let!(:jerk) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||||
let!(:neil) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
|
||||||
let!(:larry) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
let!(:larry) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||||
|
|
||||||
context 'with follows and blocks' do
|
context 'with follows and blocks' do
|
||||||
|
@ -70,13 +70,31 @@ RSpec.describe AccountSuggestions::FriendsOfFriendsSource do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns eligible accounts in the expected order' do
|
it 'returns eligible accounts in the expected order' do
|
||||||
expect(subject.get(bob)).to eq [
|
expect(subject.get(bob)).to eq expected_results
|
||||||
[eugen.id, :friends_of_friends], # followed by 2 friends, 3 followers total
|
end
|
||||||
[john.id, :friends_of_friends], # followed by 2 friends, 2 followers total
|
|
||||||
[neil.id, :friends_of_friends], # followed by 1 friend, 2 followers total
|
it 'contains correct underlying source data' do
|
||||||
[jerk.id, :friends_of_friends], # followed by 1 friend, 1 follower total
|
expect(source_query_values)
|
||||||
|
.to contain_exactly(
|
||||||
|
[eugen.id, 2, 3], # Followed by 2 friends of bob (eve, mallory), 3 followers total (breaks tie)
|
||||||
|
[john.id, 2, 2], # Followed by 2 friends of bob (eve, mallory), 2 followers total
|
||||||
|
[neil.id, 1, 2], # Followed by 1 friends of bob (mallory), 2 followers total (breaks tie)
|
||||||
|
[jerk.id, 1, 1] # Followed by 1 friends of bob (eve), 1 followers total
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def expected_results
|
||||||
|
[
|
||||||
|
[eugen.id, :friends_of_friends],
|
||||||
|
[john.id, :friends_of_friends],
|
||||||
|
[neil.id, :friends_of_friends],
|
||||||
|
[jerk.id, :friends_of_friends],
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def source_query_values
|
||||||
|
subject.source_query(bob).to_a
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue