Merge branch 'refactor/object-cache-deletion' into 'develop'
refactor object cache deletion See merge request pleroma/pleroma!408
This commit is contained in:
commit
68a1405643
@ -1,6 +1,6 @@
|
||||
defmodule Pleroma.Object do
|
||||
use Ecto.Schema
|
||||
alias Pleroma.{Repo, Object}
|
||||
alias Pleroma.{Repo, Object, Activity}
|
||||
import Ecto.{Query, Changeset}
|
||||
|
||||
schema "objects" do
|
||||
@ -52,4 +52,12 @@ defmodule Pleroma.Object do
|
||||
def context_mapping(context) do
|
||||
Object.change(%Object{}, %{data: %{"id" => context}})
|
||||
end
|
||||
|
||||
def delete(%Object{data: %{"id" => id}} = object) do
|
||||
with Repo.delete(object),
|
||||
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
|
||||
{:ok, true} <- Cachex.del(:user_cache, "object:#{id}") do
|
||||
:ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -273,8 +273,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||
"to" => [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"]
|
||||
}
|
||||
|
||||
with Repo.delete(object),
|
||||
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
|
||||
with Object.delete(object),
|
||||
{:ok, activity} <- insert(data, local),
|
||||
:ok <- maybe_federate(activity),
|
||||
{:ok, _actor} <- User.decrease_note_count(user) do
|
||||
|
@ -9,8 +9,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||
with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id),
|
||||
%Object{} = object <- Object.normalize(object_id),
|
||||
true <- user.info["is_moderator"] || user.ap_id == object.data["actor"],
|
||||
{:ok, delete} <- ActivityPub.delete(object),
|
||||
{:ok, true} <- Cachex.del(:user_cache, "object:#{object_id}") do
|
||||
{:ok, delete} <- ActivityPub.delete(object) do
|
||||
{:ok, delete}
|
||||
end
|
||||
end
|
||||
|
@ -19,4 +19,34 @@ defmodule Pleroma.ObjectTest do
|
||||
{:error, _result} = Repo.insert(cs)
|
||||
end
|
||||
end
|
||||
|
||||
describe "deletion function" do
|
||||
test "deletes an object" do
|
||||
object = insert(:note)
|
||||
found_object = Object.get_by_ap_id(object.data["id"])
|
||||
|
||||
assert object == found_object
|
||||
|
||||
Object.delete(found_object)
|
||||
|
||||
found_object = Object.get_by_ap_id(object.data["id"])
|
||||
|
||||
refute object == found_object
|
||||
end
|
||||
|
||||
test "ensures cache is cleared for the object" do
|
||||
object = insert(:note)
|
||||
cached_object = Object.get_cached_by_ap_id(object.data["id"])
|
||||
|
||||
assert object == cached_object
|
||||
|
||||
Object.delete(cached_object)
|
||||
|
||||
{:ok, nil} = Cachex.get(:user_cache, "object:#{object.data["id"]}")
|
||||
|
||||
cached_object = Object.get_cached_by_ap_id(object.data["id"])
|
||||
|
||||
refute object == cached_object
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user