From: Eugen Rochko Date: Thu, 16 Mar 2017 19:10:51 +0000 (+0100) Subject: Add method for retrieving triadic closures X-Git-Url: https://git.xn--scling-oua.cat.family/?a=commitdiff_plain;h=017350e0ead4715ef4180eb7b1f6fecb67fbf554;p=mastodon.git Add method for retrieving triadic closures --- diff --git a/app/models/account.rb b/app/models/account.rb index 078078945..1eb886ee3 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -193,6 +193,25 @@ class Account < ApplicationRecord nil end + def triadic_closures(account, limit = 5) + sql = < ? + GROUP BY target_account_id, accounts.id + ORDER BY count(account_id) DESC + LIMIT ? +SQL + + Account.find_by_sql([sql, account.id, account.id, limit]) + end + def following_map(target_account_ids, account_id) follow_mapping(Follow.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id) end