fix cache keys

This commit is contained in:
Maksim Pechnikov 2020-06-04 17:01:45 +03:00
parent 3fd2795412
commit 03369b5c4a
3 changed files with 12 additions and 13 deletions

View File

@ -92,14 +92,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
def maybe_remove_mediaproxy_invalidation(true, %{
"object" => %{"attachment" => [_ | _] = attachments}
}) do
Task.start(fn ->
attachments
|> Enum.flat_map(fn
%{"url" => urls} -> Enum.map(urls, &MediaProxy.url(&1["href"]))
_ -> []
end)
|> MediaProxy.remove_from_deleted_urls()
attachments
|> Enum.flat_map(fn
%{"url" => urls} -> Enum.map(urls, & &1["href"])
_ -> []
end)
|> MediaProxy.remove_from_deleted_urls()
:ok
end

View File

@ -28,7 +28,7 @@ defmodule Pleroma.Web.MediaProxy.Invalidation do
provider.purge(urls, Config.get(provider))
end
defp prepare_urls(urls) do
def prepare_urls(urls) do
urls
|> List.wrap()
|> Enum.map(&MediaProxy.url(&1))

View File

@ -6,30 +6,31 @@ defmodule Pleroma.Web.MediaProxy do
alias Pleroma.Config
alias Pleroma.Upload
alias Pleroma.Web
alias Pleroma.Web.MediaProxy.Invalidation
@base64_opts [padding: false]
@spec in_deleted_urls(String.t()) :: boolean()
def in_deleted_urls(url), do: elem(Cachex.exists?(:deleted_urls_cache, url), 1)
def in_deleted_urls(url), do: elem(Cachex.exists?(:deleted_urls_cache, url(url)), 1)
def remove_from_deleted_urls(urls) when is_list(urls) do
Cachex.execute!(:deleted_urls_cache, fn cache ->
Enum.each(urls, &Cachex.del(cache, &1))
Enum.each(Invalidation.prepare_urls(urls), &Cachex.del(cache, &1))
end)
end
def remove_from_deleted_urls(url) when is_binary(url) do
Cachex.del(:deleted_urls_cache, url)
Cachex.del(:deleted_urls_cache, url(url))
end
def put_in_deleted_urls(urls) when is_list(urls) do
Cachex.execute!(:deleted_urls_cache, fn cache ->
Enum.each(urls, &Cachex.put(cache, &1, true))
Enum.each(Invalidation.prepare_urls(urls), &Cachex.put(cache, &1, true))
end)
end
def put_in_deleted_urls(url) when is_binary(url) do
Cachex.put(:deleted_urls_cache, url, true)
Cachex.put(:deleted_urls_cache, url(url), true)
end
def url(url) when is_nil(url) or url == "", do: nil