Skip to content
Snippets Groups Projects
Commit 69643338 authored by Eugen's avatar Eugen Committed by GitHub
Browse files

Merge pull request #437 from krainboltgreene/patch-1

Simplifying followers mappings
parents e8d6f6c8 abe3ae1c
No related branches found
No related tags found
No related merge requests found
......@@ -175,19 +175,23 @@ class Account < ApplicationRecord
end
def following_map(target_account_ids, account_id)
Follow.where(target_account_id: target_account_ids).where(account_id: account_id).map { |f| [f.target_account_id, true] }.to_h
follow_mapping(Follow.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
end
def followed_by_map(target_account_ids, account_id)
Follow.where(account_id: target_account_ids).where(target_account_id: account_id).map { |f| [f.account_id, true] }.to_h
follow_mapping(Follow.where(account_id: target_account_ids, target_account_id: account_id), :account_id)
end
def blocking_map(target_account_ids, account_id)
Block.where(target_account_id: target_account_ids).where(account_id: account_id).map { |b| [b.target_account_id, true] }.to_h
follow_mapping(Block.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
end
def requested_map(target_account_ids, account_id)
FollowRequest.where(target_account_id: target_account_ids).where(account_id: account_id).map { |r| [r.target_account_id, true] }.to_h
follow_mapping(FollowRequest.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
end
private def follow_mapping(query, field)
query.pluck(field).inject({}) { |mapping, id| mapping[id] = true }
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment