From: William Pitcock Date: Thu, 1 Nov 2018 07:28:48 +0000 (+0000) Subject: object: add safe object deletion function X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=c4e43da63e03f66fd2feaa192c4d8192bbc3451c;p=akkoma object: add safe object deletion function --- diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 1bcff5a7b..8f96fd8fb 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -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