From 47b9847edd74c394e2bdfcb95a42f858329c9ef1 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sun, 13 Nov 2022 12:25:52 -0500 Subject: [PATCH 1/2] Deletes do not generate notifications of any kind, so skip trying --- CHANGELOG.md | 1 + lib/pleroma/web/activity_pub/side_effects.ex | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 889a3ebfe..141cc2e40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fixed slow timelines when there are a lot of deactivated users - Fixed account deletion API - Fixed lowercase HTTP HEAD method in the Media Proxy Preview code +- Removed useless notification call on Delete activities ### Removed - Quack, the logging backend that pushes to Slack channels diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex index 5eefd2824..b2e15e1a0 100644 --- a/lib/pleroma/web/activity_pub/side_effects.ex +++ b/lib/pleroma/web/activity_pub/side_effects.ex @@ -324,7 +324,6 @@ def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, end if result == :ok do - Notification.create_notifications(object) {:ok, object, meta} else {:error, result} From 2e0089dd5c27c86488d2c68170d80d02c24135f3 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sun, 13 Nov 2022 13:33:27 -0500 Subject: [PATCH 2/2] Alter priority of Delete activities to be lowest This will prevent a user with a large number of posts from negatively affecting performance of the outgoing federation queue if they delete their account. --- CHANGELOG.md | 1 + lib/pleroma/web/activity_pub/side_effects.ex | 1 - lib/pleroma/web/federator.ex | 9 ++++- .../pleroma/workers/publisher_worker_test.exs | 40 +++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 test/pleroma/workers/publisher_worker_test.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 141cc2e40..56f328234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - **Breaking**: `/api/v1/pleroma/backups` endpoints now requires `read:backups` scope instead of `read:accounts` - Updated the recommended pleroma.vcl configuration for Varnish to target Varnish 7.0+ - Set timeout values for Oban queues. The default is infinity and some operations may not time out on their own. +- Delete activities are federated at lowest priority ### Added - `activeMonth` and `activeHalfyear` fields in NodeInfo usage.users object diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex index b2e15e1a0..a2152b945 100644 --- a/lib/pleroma/web/activity_pub/side_effects.ex +++ b/lib/pleroma/web/activity_pub/side_effects.ex @@ -282,7 +282,6 @@ def handle(%{data: %{"type" => "EmojiReact"}} = object, meta) do # Tasks this handles: # - Delete and unpins the create activity # - Replace object with Tombstone - # - Set up notification # - Reduce the user note count # - Reduce the reply count # - Stream out the activity diff --git a/lib/pleroma/web/federator.ex b/lib/pleroma/web/federator.ex index 3be71c1b6..318b6cb11 100644 --- a/lib/pleroma/web/federator.ex +++ b/lib/pleroma/web/federator.ex @@ -47,10 +47,15 @@ def publish(%{id: "pleroma:fakeid"} = activity) do end @impl true - def publish(activity) do - PublisherWorker.enqueue("publish", %{"activity_id" => activity.id}) + def publish(%Pleroma.Activity{data: %{"type" => type}} = activity) do + PublisherWorker.enqueue("publish", %{"activity_id" => activity.id}, + priority: publish_priority(type) + ) end + defp publish_priority("Delete"), do: 3 + defp publish_priority(_), do: 0 + # Job Worker Callbacks @spec perform(atom(), module(), any()) :: {:ok, any()} | {:error, any()} diff --git a/test/pleroma/workers/publisher_worker_test.exs b/test/pleroma/workers/publisher_worker_test.exs new file mode 100644 index 000000000..13372bf49 --- /dev/null +++ b/test/pleroma/workers/publisher_worker_test.exs @@ -0,0 +1,40 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Workers.PublisherWorkerTest do + use Pleroma.DataCase, async: true + use Oban.Testing, repo: Pleroma.Repo + + import Pleroma.Factory + + alias Pleroma.Object + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Builder + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.Federator + + describe "Oban job priority:" do + setup do + user = insert(:user) + + {:ok, post} = CommonAPI.post(user, %{status: "Regrettable post"}) + object = Object.normalize(post, fetch: false) + {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"]) + {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true) + + %{ + post: post, + delete: delete + } + end + + test "Deletions are lower priority", %{delete: delete} do + assert {:ok, %Oban.Job{priority: 3}} = Federator.publish(delete) + end + + test "Creates are normal priority", %{post: post} do + assert {:ok, %Oban.Job{priority: 0}} = Federator.publish(post) + end + end +end