diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2021-04-12 12:37:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-12 12:37:14 +0200 |
commit | f7117646afddb2676e9275d8efe90c3a20c59021 (patch) | |
tree | efb9ba8f7b22d27b0a1ea595cfa30030f5d03b09 /app/lib | |
parent | ad61265268f13d9b2a04e2e176724d8a7376f85a (diff) |
Add cold-start follow recommendations (#15945)
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/potential_friendship_tracker.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/app/lib/potential_friendship_tracker.rb b/app/lib/potential_friendship_tracker.rb index 188aa4a27..e72d454b6 100644 --- a/app/lib/potential_friendship_tracker.rb +++ b/app/lib/potential_friendship_tracker.rb @@ -28,10 +28,14 @@ class PotentialFriendshipTracker redis.zrem("interactions:#{account_id}", target_account_id) end - def get(account_id, limit: 20, offset: 0) - account_ids = redis.zrevrange("interactions:#{account_id}", offset, limit) - return [] if account_ids.empty? - Account.searchable.where(id: account_ids) + def get(account, limit) + account_ids = redis.zrevrange("interactions:#{account.id}", 0, limit) + + return [] if account_ids.empty? || limit < 1 + + accounts = Account.searchable.where(id: account_ids).index_by(&:id) + + account_ids.map { |id| accounts[id.to_i] }.compact end end end |