activity: when restricting deactivated users, precalculate the user list
authorAriadne Conill <ariadne@dereferenced.org>
Fri, 6 Sep 2019 23:14:29 +0000 (23:14 +0000)
committerAriadne Conill <ariadne@dereferenced.org>
Fri, 6 Sep 2019 23:14:29 +0000 (23:14 +0000)
the PostgreSQL query planner is easily confused due to the complexity of
certain queries we make.  while we plan to simplify these queries through
unification of activities and objects, we are not yet there.  it has been
discovered that using a precalculated list of deactivated users encourages
the query planner to prefer simpler indices instead of the
activity_visibility index.

accordingly, drop the subquery and precalc the user list instead.

lib/pleroma/activity.ex

index 2d4e9da0c7e9c8b269d24fd2ebace82e8f4442c6..a7844c36bc909f9985c2ece2bb3c1dc100db34f9 100644 (file)
@@ -362,12 +362,12 @@ defmodule Pleroma.Activity do
   end
 
   def restrict_deactivated_users(query) do
+    deactivated_users =
+      from(u in User.Query.build(deactivated: true), select: u.ap_id)
+      |> Repo.all()
+
     from(activity in query,
-      where:
-        fragment(
-          "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')",
-          activity.actor
-        )
+      where: activity.actor not in ^deactivated_users
     )
   end