From: lain Date: Mon, 6 Dec 2021 19:55:52 +0000 (+0000) Subject: Merge branch 'optimisation/deactivated-subquery' into 'develop' X-Git-Url: http://git.squeep.com/?a=commitdiff_plain;h=ab60c0c6c2145df145a71f6786bd087ea8304596;hp=5c573a8a282725a9f2595fa264d794870a832a8a;p=akkoma Merge branch 'optimisation/deactivated-subquery' into 'develop' Make deactivated user check into a subquery Closes #2792 See merge request pleroma/pleroma!3554 --- diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index b88f74f47..4106feef6 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -362,11 +362,9 @@ 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() + deactivated_users_query = from(u in User.Query.build(%{deactivated: true}), select: u.ap_id) - Activity.Queries.exclude_authors(query, deactivated_users) + from(activity in query, where: activity.actor not in subquery(deactivated_users_query)) end defdelegate search(user, query, options \\ []), to: Pleroma.Activity.Search diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index a61244c76..574ef0d71 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -776,6 +776,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert Enum.member?(activities, activity_one) end + test "doesn't return activities from deactivated users" do + _user = insert(:user) + deactivated = insert(:user) + active = insert(:user) + {:ok, activity_one} = CommonAPI.post(deactivated, %{status: "hey!"}) + {:ok, activity_two} = CommonAPI.post(active, %{status: "yay!"}) + {:ok, _updated_user} = User.set_activation(deactivated, false) + + activities = ActivityPub.fetch_activities([], %{}) + + refute Enum.member?(activities, activity_one) + assert Enum.member?(activities, activity_two) + end + test "always see your own posts even when they address people you block" do user = insert(:user) blockee = insert(:user)