From 5effb2cbca51534a68dad1c5a4dd24b1ae08360a Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 6 Sep 2019 23:11:26 +0000 Subject: [PATCH 1/2] activitypub: help ecto build a better query for thread mute filtering using an indexed value in thread_mute table helps ecto build a better query. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index eeb826814..d23ec66ac 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -796,7 +796,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do ) unless opts["skip_preload"] do - from([thread_mute: tm] in query, where: is_nil(tm)) + from([thread_mute: tm] in query, where: is_nil(tm.user_id)) else query end From 40a61532cadbac8b196917c6f5843c3f6cd7e78b Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 6 Sep 2019 23:14:29 +0000 Subject: [PATCH 2/2] activity: when restricting deactivated users, precalculate the user list 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 2d4e9da0c..a7844c36b 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -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