From f4e087ee485bd6766e426627eeaa729779b5eabc Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 14 Aug 2019 02:36:54 +0300 Subject: [PATCH] Preload thread mutes/bookmarks in get_context Also removes filtering for creates (was done on the database side already) and filtering for the requested activity (moved to the database side) from application side. --- lib/pleroma/web/activity_pub/activity_pub.ex | 9 +++++++++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 7 ++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 1a279a7df..d473a3ed9 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -518,6 +518,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do from(activity in Activity) |> maybe_preload_objects(opts) + |> maybe_preload_bookmarks(opts) + |> maybe_set_thread_muted_field(opts) |> restrict_blocked(opts) |> restrict_recipients(recipients, opts["user"]) |> where( @@ -531,6 +533,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do ) ) |> exclude_poll_votes(opts) + |> exclude_id(opts) |> order_by([activity], desc: activity.id) end @@ -870,6 +873,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end + defp exclude_id(query, %{"exclude_id" => id}) when is_binary(id) do + from(activity in query, where: activity.id != ^id) + end + + defp exclude_id(query, _), do: query + defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query defp maybe_preload_objects(query, _) do diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index c3c75bd9a..7ce2b5b06 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -497,12 +497,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do activities <- ActivityPub.fetch_activities_for_context(activity.data["context"], %{ "blocking_user" => user, - "user" => user + "user" => user, + "exclude_id" => activity.id }), - activities <- - activities |> Enum.filter(fn %{id: aid} -> to_string(aid) != to_string(id) end), - activities <- - activities |> Enum.filter(fn %{data: %{"type" => type}} -> type == "Create" end), grouped_activities <- Enum.group_by(activities, fn %{id: id} -> id < activity.id end) do result = %{ ancestors: -- 2.45.2