From 856c57208bbf0a4a88f33f922a3a96b037285d89 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Tue, 11 Oct 2022 14:30:08 +0100 Subject: [PATCH] Ensure deletes are handled after everything else --- CHANGELOG.md | 1 + config/config.exs | 5 ++++- lib/mix/tasks/pleroma/user.ex | 6 ++++++ lib/pleroma/web/activity_pub/side_effects.ex | 2 -- lib/pleroma/web/federator.ex | 15 +++++++++++---- lib/pleroma/web/mastodon_api/mastodon_api.ex | 15 +++++---------- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a675a32e..cbe09d598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Changes - Follows no longer override domain blocks, a domain block is final +- Deletes are now the lowest priority to publish and will be handled after creates ## 2022.10 diff --git a/config/config.exs b/config/config.exs index d7005770e..5eb82cd33 100644 --- a/config/config.exs +++ b/config/config.exs @@ -569,7 +569,10 @@ mute_expire: 5, search_indexing: 10 ], - plugins: [Oban.Plugins.Pruner], + plugins: [ + Oban.Plugins.Pruner, + {Oban.Plugins.Reindexer, schedule: "@weekly"} + ], crontab: [ {"0 0 * * 0", Pleroma.Workers.Cron.DigestEmailsWorker}, {"0 0 * * *", Pleroma.Workers.Cron.NewUsersDigestWorker} diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index f420d68bb..50c3fd7ce 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -538,6 +538,12 @@ def run(["fix_follow_state", local_user, remote_user]) do end end + def run(["convert_id", id]) do + {:ok, uuid} = FlakeId.Ecto.Type.dump(id) + {:ok, raw_id} = Ecto.UUID.load(uuid) + shell_info(raw_id) + end + defp refetch_public_keys(query) do query |> Pleroma.Repo.chunk_stream(50, :batches) diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex index 43b1b089b..c3258c75b 100644 --- a/lib/pleroma/web/activity_pub/side_effects.ex +++ b/lib/pleroma/web/activity_pub/side_effects.ex @@ -323,8 +323,6 @@ def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, end if result == :ok do - Notification.create_notifications(object) - # Only remove from index when deleting actual objects, not users or anything else with %Pleroma.Object{} <- deleted_object do Pleroma.Search.remove_from_index(deleted_object) diff --git a/lib/pleroma/web/federator.ex b/lib/pleroma/web/federator.ex index bc61130f1..770044de2 100644 --- a/lib/pleroma/web/federator.ex +++ b/lib/pleroma/web/federator.ex @@ -53,12 +53,19 @@ def publish(%{data: %{"object" => object}} = activity) when is_binary(object) do @impl true def publish(%{data: %{"object" => object}} = activity) when is_map(object) or is_list(object) do - PublisherWorker.enqueue("publish", %{ - "activity_id" => activity.id, - "object_data" => Jason.encode!(object) - }) + PublisherWorker.enqueue( + "publish", + %{ + "activity_id" => activity.id, + "object_data" => Jason.encode!(object) + }, + priority: publish_priority(activity) + ) end + defp publish_priority(%{type: "Delete"}), do: 3 + defp publish_priority(_), do: 0 + # Job Worker Callbacks @spec perform(atom(), module(), any()) :: {:ok, any()} | {:error, any()} diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex index 69bc2f0d6..23846b36a 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex @@ -63,16 +63,11 @@ def get_friends(user, params \\ %{}) do def get_notifications(user, params \\ %{}) do options = cast_params(params) - query = - user - |> Notification.for_user_query(options) - |> restrict(:include_types, options) - |> restrict(:exclude_types, options) - |> restrict(:account_ap_id, options) - - IO.inspect(Pleroma.Repo.to_sql(:all, query)) - - query + user + |> Notification.for_user_query(options) + |> restrict(:include_types, options) + |> restrict(:exclude_types, options) + |> restrict(:account_ap_id, options) |> Pagination.fetch_paginated(params) end