From 08d60ce6672ef502231bd3ef04e0ee8e3a59db47 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sun, 25 Aug 2019 23:23:53 +0000 Subject: [PATCH] activitypub: remove thread_visibility() SQL function calls --- lib/pleroma/web/activity_pub/activity_pub.ex | 24 ------------------------ lib/pleroma/web/activity_pub/visibility.ex | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 172c952d4..ab29ee497 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -604,25 +604,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_visibility(query, _visibility), do: query - defp restrict_thread_visibility(query, _, %{skip_thread_containment: true} = _), - do: query - - defp restrict_thread_visibility( - query, - %{"user" => %User{info: %{skip_thread_containment: true}}}, - _ - ), - do: query - - defp restrict_thread_visibility(query, %{"user" => %User{ap_id: ap_id}}, _) do - from( - a in query, - where: fragment("thread_visibility(?, (?)->>'id') = true", ^ap_id, a.data) - ) - end - - defp restrict_thread_visibility(query, _, _), do: query - def fetch_user_activities(user, reading_user, params \\ %{}) do params = params @@ -921,10 +902,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp maybe_order(query, _), do: query def fetch_activities_query(recipients, opts \\ %{}) do - config = %{ - skip_thread_containment: Config.get([:instance, :skip_thread_containment]) - } - Activity |> maybe_preload_objects(opts) |> maybe_preload_bookmarks(opts) @@ -944,7 +921,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> restrict_muted(opts) |> restrict_media(opts) |> restrict_visibility(opts) - |> restrict_thread_visibility(opts, config) |> restrict_replies(opts) |> restrict_reblogs(opts) |> restrict_pinned(opts) diff --git a/lib/pleroma/web/activity_pub/visibility.ex b/lib/pleroma/web/activity_pub/visibility.ex index dfb166b65..398c65d97 100644 --- a/lib/pleroma/web/activity_pub/visibility.ex +++ b/lib/pleroma/web/activity_pub/visibility.ex @@ -5,7 +5,6 @@ defmodule Pleroma.Web.ActivityPub.Visibility do alias Pleroma.Activity alias Pleroma.Object - alias Pleroma.Repo alias Pleroma.User require Pleroma.Constants @@ -58,14 +57,21 @@ defmodule Pleroma.Web.ActivityPub.Visibility do visible_for_user?(activity, nil) || Enum.any?(x, &(&1 in y)) end - def entire_thread_visible_for_user?(%Activity{} = activity, %User{} = user) do - {:ok, %{rows: [[result]]}} = - Ecto.Adapters.SQL.query(Repo, "SELECT thread_visibility($1, $2)", [ - user.ap_id, - activity.data["id"] - ]) + # XXX: Probably even more inefficient than the previous implementation intended to be a placeholder untill https://git.pleroma.social/pleroma/pleroma/merge_requests/971 is in develop + # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength + def entire_thread_visible_for_user?( + %Activity{} = tail, + # %Activity{data: %{"object" => %{"inReplyTo" => parent_id}}} = tail, + user + ) do + case Object.normalize(tail) do + %{data: %{"inReplyTo" => parent_id}} when is_binary(parent_id) -> + parent = Activity.get_in_reply_to_activity(tail) + visible_for_user?(tail, user) && entire_thread_visible_for_user?(parent, user) - result + _ -> + visible_for_user?(tail, user) + end end def get_visibility(object) do