mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-11-14 13:02:08 +00:00
Fix RichMedia negative cache entries
The negative cache entry was a nil value, but that is an expected response when the cache is missing an entry so it didn't work as intended.
This commit is contained in:
parent
5a62868106
commit
97d488aea3
2 changed files with 27 additions and 1 deletions
|
@ -64,5 +64,5 @@ defmodule Pleroma.Web.RichMedia.Backfill do
|
||||||
defp warm_cache(key, val), do: @cachex.put(:rich_media_cache, key, val)
|
defp warm_cache(key, val), do: @cachex.put(:rich_media_cache, key, val)
|
||||||
|
|
||||||
defp negative_cache(key, ttl \\ :timer.minutes(15)),
|
defp negative_cache(key, ttl \\ :timer.minutes(15)),
|
||||||
do: @cachex.put(:rich_media_cache, key, nil, ttl: ttl)
|
do: @cachex.put(:rich_media_cache, key, :error, ttl: ttl)
|
||||||
end
|
end
|
||||||
|
|
26
test/pleroma/web/rich_media/backfill_test.exs
Normal file
26
test/pleroma/web/rich_media/backfill_test.exs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.RichMedia.BackfillTest do
|
||||||
|
use Pleroma.DataCase
|
||||||
|
|
||||||
|
alias Pleroma.Web.RichMedia.Backfill
|
||||||
|
alias Pleroma.Web.RichMedia.Card
|
||||||
|
|
||||||
|
import Mox
|
||||||
|
|
||||||
|
setup_all do: clear_config([:rich_media, :enabled], true)
|
||||||
|
|
||||||
|
test "sets a negative cache entry for an error" do
|
||||||
|
url = "https://bad.example.com/"
|
||||||
|
url_hash = Card.url_to_hash(url)
|
||||||
|
|
||||||
|
Tesla.Mock.mock(fn %{url: ^url} -> :error end)
|
||||||
|
|
||||||
|
Pleroma.CachexMock
|
||||||
|
|> expect(:put, fn :rich_media_cache, ^url_hash, :error, ttl: _ -> {:ok, true} end)
|
||||||
|
|
||||||
|
Backfill.run(%{"url" => url})
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue