remove deleted media urls from cache
This commit is contained in:
parent
ddb91106b6
commit
e4e96ea914
@ -20,6 +20,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
alias Pleroma.Web.MediaProxy
|
||||||
alias Pleroma.Web.Streamer
|
alias Pleroma.Web.Streamer
|
||||||
alias Pleroma.Web.WebFinger
|
alias Pleroma.Web.WebFinger
|
||||||
alias Pleroma.Workers.BackgroundWorker
|
alias Pleroma.Workers.BackgroundWorker
|
||||||
@ -87,6 +88,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
|
|
||||||
defp check_remote_limit(_), do: true
|
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
|
def increase_note_count_if_public(actor, object) do
|
||||||
if is_public?(object), do: User.increase_note_count(actor), else: {:ok, actor}
|
if is_public?(object), do: User.increase_note_count(actor), else: {:ok, actor}
|
||||||
end
|
end
|
||||||
@ -275,16 +294,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
{:fake, false, activity} <- {:fake, fake, activity},
|
{:fake, false, activity} <- {:fake, fake, activity},
|
||||||
_ <- increase_replies_count_if_reply(create_data),
|
_ <- increase_replies_count_if_reply(create_data),
|
||||||
_ <- increase_poll_votes_if_vote(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},
|
{:quick_insert, false, activity} <- {:quick_insert, quick_insert?, activity},
|
||||||
{:ok, _actor} <- increase_note_count_if_public(actor, activity),
|
{:ok, _actor} <- increase_note_count_if_public(actor, activity),
|
||||||
_ <- notify_and_stream(activity),
|
_ <- notify_and_stream(activity),
|
||||||
:ok <- maybe_federate(activity) do
|
:ok <- maybe_federate(activity) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
{:quick_insert, true, activity} ->
|
{type, true, activity} when type in [:fake, :quick_insert] ->
|
||||||
{:ok, activity}
|
|
||||||
|
|
||||||
{:fake, true, activity} ->
|
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
|
||||||
{:error, message} ->
|
{:error, message} ->
|
||||||
|
@ -68,16 +68,10 @@ defmodule Pleroma.Workers.AttachmentsCleanupWorker do
|
|||||||
|
|
||||||
def perform(%{"op" => "cleanup_attachments", "object" => _object}, _job), do: {:ok, :skip}
|
def perform(%{"op" => "cleanup_attachments", "object" => _object}, _job), do: {:ok, :skip}
|
||||||
|
|
||||||
defp cache_purge(true, attachment_urls) do
|
defp cache_purge(true, urls), do: MediaProxy.Invalidation.purge(urls)
|
||||||
MediaProxy.Invalidation.purge(attachment_urls)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp cache_purge(_, _), do: :ok
|
defp cache_purge(_, _), do: :ok
|
||||||
|
|
||||||
defp lock_attachments(true, attachment_urls) do
|
defp lock_attachments(true, urls), do: MediaProxy.put_in_deleted_urls(urls)
|
||||||
MediaProxy.put_in_deleted_urls(attachment_urls)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp lock_attachments(_, _), do: :ok
|
defp lock_attachments(_, _), do: :ok
|
||||||
|
|
||||||
# we should delete 1 object for any given attachment, but don't delete
|
# we should delete 1 object for any given attachment, but don't delete
|
||||||
|
Loading…
Reference in New Issue
Block a user