Merge remote-tracking branch 'remotes/origin/develop' into feature/object-hashtags-rework

This commit is contained in:
Ivan Tashkinov 2020-12-26 22:23:05 +03:00
commit 4134abef63
205 changed files with 682 additions and 443 deletions

View file

@ -24,6 +24,8 @@ defmodule Pleroma.Object do
@derive {Jason.Encoder, only: [:data]}
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
schema "objects" do
field(:data, :map)
@ -189,9 +191,9 @@ defmodule Pleroma.Object do
def get_cached_by_ap_id(ap_id) do
key = "object:#{ap_id}"
with {:ok, nil} <- Cachex.get(:object_cache, key),
with {:ok, nil} <- @cachex.get(:object_cache, key),
object when not is_nil(object) <- get_by_ap_id(ap_id),
{:ok, true} <- Cachex.put(:object_cache, key, object) do
{:ok, true} <- @cachex.put(:object_cache, key, object) do
object
else
{:ok, object} -> object
@ -249,13 +251,13 @@ defmodule Pleroma.Object do
end
def invalid_object_cache(%Object{data: %{"id" => id}}) do
with {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
Cachex.del(:web_resp_cache, URI.parse(id).path)
with {:ok, true} <- @cachex.del(:object_cache, "object:#{id}") do
@cachex.del(:web_resp_cache, URI.parse(id).path)
end
end
def set_cache(%Object{data: %{"id" => ap_id}} = object) do
Cachex.put(:object_cache, "object:#{ap_id}", object)
@cachex.put(:object_cache, "object:#{ap_id}", object)
{:ok, object}
end