Add same optimized join for excluding invisible users
authorMark Felder <feld@feld.me>
Sat, 12 Nov 2022 23:05:58 +0000 (18:05 -0500)
committerFrancis Dinh <normandy@biribiri.dev>
Sat, 19 Nov 2022 20:12:24 +0000 (15:12 -0500)
lib/pleroma/web/activity_pub/activity_pub.ex

index 5f7541b027df388afe975dda6d50f6498ea55880..3a9b08cf05d39bfa74167ceb7c7c41e9ca843838 100644 (file)
@@ -1251,12 +1251,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   defp exclude_invisible_actors(query, %{invisible_actors: true}), do: query
 
   defp exclude_invisible_actors(query, _opts) do
-    invisible_ap_ids =
-      User.Query.build(%{invisible: true, select: [:ap_id]})
-      |> Repo.all()
-      |> Enum.map(fn %{ap_id: ap_id} -> ap_id end)
-
-    from([activity] in query, where: activity.actor not in ^invisible_ap_ids)
+    query
+    |> join(:inner, [activity], u in User,
+      as: :u,
+      on: activity.actor == u.ap_id and u.invisible == false
+    )
   end
 
   defp exclude_id(query, %{exclude_id: id}) when is_binary(id) do