From: kaniini Date: Sun, 3 Mar 2019 15:51:32 +0000 (+0000) Subject: Merge branch 'get-follow-requests-sql' into 'develop' X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=b531e366dfffa6b34900dd249492707bff647401;p=akkoma Merge branch 'get-follow-requests-sql' into 'develop' Use sql query in User.get_follow_requests/1 for filtering logic See merge request pleroma/pleroma!883 --- b531e366dfffa6b34900dd249492707bff647401 diff --cc lib/pleroma/user.ex index 82922d236,06b430ccd..d69ca094e --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@@ -621,24 -621,16 +621,23 @@@ defmodule Pleroma.User d ) end - def update_follow_request_count(%User{} = user) do - subquery = + def get_follow_requests(%User{} = user) do - q = get_follow_requests_query(user) - reqs = Repo.all(q) - + users = - Enum.map(reqs, fn req -> req.actor end) - |> Enum.uniq() - |> Enum.map(fn ap_id -> get_by_ap_id(ap_id) end) - |> Enum.filter(fn u -> !is_nil(u) end) - |> Enum.filter(fn u -> !following?(u, user) end) + user + |> User.get_follow_requests_query() - |> select([a], %{count: count(a.id)}) ++ |> join(:inner, [a], u in User, a.actor == u.ap_id) ++ |> where([a, u], not fragment("? @> ?", u.following, ^[user.follower_address])) ++ |> group_by([a, u], u.id) ++ |> select([a, u], u) ++ |> Repo.all() + + {:ok, users} + end + def increase_note_count(%User{} = user) do User |> where(id: ^user.id) - |> join(:inner, [u], s in subquery(subquery)) - |> update([u, s], + |> update([u], set: [ info: fragment(