user: factor out user set fetching from User.get_notified_from_activity()

This commit is contained in:
William Pitcock 2018-11-09 08:23:45 +00:00
parent 81d6ca1783
commit d26cd6c1bf

View File

@ -464,15 +464,15 @@ defmodule Pleroma.User do
update_and_set_cache(cs) update_and_set_cache(cs)
end end
def get_notified_from_activity_query(to, false) do def get_users_from_set_query(ap_ids, false) do
from( from(
u in User, u in User,
where: u.ap_id in ^to where: u.ap_id in ^ap_ids
) )
end end
def get_notified_from_activity_query(to, true) do def get_users_from_set_query(ap_ids, true) do
query = get_notified_from_activity_query(to, false) query = get_users_from_set_query(ap_ids, false)
from( from(
u in query, u in query,
@ -480,6 +480,11 @@ defmodule Pleroma.User do
) )
end end
def get_users_from_set(ap_ids, local_only \\ true) do
get_users_from_set_query(ap_ids, local_only)
|> Repo.all()
end
def get_notified_from_activity(activity, local_only \\ true) def get_notified_from_activity(activity, local_only \\ true)
def get_notified_from_activity(%Activity{data: %{"to" => to} = data}, local_only) do def get_notified_from_activity(%Activity{data: %{"to" => to} = data}, local_only) do
@ -513,9 +518,7 @@ defmodule Pleroma.User do
(to ++ tagged_mentions) (to ++ tagged_mentions)
|> Enum.uniq() |> Enum.uniq()
query = get_notified_from_activity_query(to, local_only) get_users_from_set(to, local_only)
Repo.all(query)
end end
def get_notified_from_activity(_, _), do: [] def get_notified_from_activity(_, _), do: []