aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex26
-rw-r--r--lib/pleroma/workers/attachments_cleanup_worker.ex10
2 files changed, 24 insertions, 12 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 0fe71694a..379c28927 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -20,6 +20,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.MediaProxy
alias Pleroma.Web.Streamer
alias Pleroma.Web.WebFinger
alias Pleroma.Workers.BackgroundWorker
@@ -87,6 +88,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp check_remote_limit(_), do: true
+ @spec remove_deleted_attachements_from_cache(boolean(), map()) :: :ok
+ def remove_deleted_attachements_from_cache(true, %{
+ "object" => %{"attachment" => [_ | _] = attachments}
+ }) do
+ Task.start(fn ->
+ attachments
+ |> Enum.flat_map(fn
+ %{"url" => urls} -> Enum.map(urls, & &1["href"])
+ _ -> []
+ end)
+ |> MediaProxy.remove_from_deleted_urls()
+ end)
+
+ :ok
+ end
+
+ def remove_deleted_attachements_from_cache(_, _), do: :ok
+
def increase_note_count_if_public(actor, object) do
if is_public?(object), do: User.increase_note_count(actor), else: {:ok, actor}
end
@@ -275,16 +294,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
{:fake, false, activity} <- {:fake, fake, activity},
_ <- increase_replies_count_if_reply(create_data),
_ <- increase_poll_votes_if_vote(create_data),
+ _ <-
+ remove_deleted_attachements_from_cache(MediaProxy.Invalidation.enabled(), create_data),
{:quick_insert, false, activity} <- {:quick_insert, quick_insert?, activity},
{:ok, _actor} <- increase_note_count_if_public(actor, activity),
_ <- notify_and_stream(activity),
:ok <- maybe_federate(activity) do
{:ok, activity}
else
- {:quick_insert, true, activity} ->
- {:ok, activity}
-
- {:fake, true, activity} ->
+ {type, true, activity} when type in [:fake, :quick_insert] ->
{:ok, activity}
{:error, message} ->
diff --git a/lib/pleroma/workers/attachments_cleanup_worker.ex b/lib/pleroma/workers/attachments_cleanup_worker.ex
index 816d681dd..c9f69e85a 100644
--- a/lib/pleroma/workers/attachments_cleanup_worker.ex
+++ b/lib/pleroma/workers/attachments_cleanup_worker.ex
@@ -68,16 +68,10 @@ defmodule Pleroma.Workers.AttachmentsCleanupWorker do
def perform(%{"op" => "cleanup_attachments", "object" => _object}, _job), do: {:ok, :skip}
- defp cache_purge(true, attachment_urls) do
- MediaProxy.Invalidation.purge(attachment_urls)
- end
-
+ defp cache_purge(true, urls), do: MediaProxy.Invalidation.purge(urls)
defp cache_purge(_, _), do: :ok
- defp lock_attachments(true, attachment_urls) do
- MediaProxy.put_in_deleted_urls(attachment_urls)
- end
-
+ defp lock_attachments(true, urls), do: MediaProxy.put_in_deleted_urls(urls)
defp lock_attachments(_, _), do: :ok
# we should delete 1 object for any given attachment, but don't delete