object: add Object.prune()
authorWilliam Pitcock <nenolod@dereferenced.org>
Tue, 21 May 2019 00:41:40 +0000 (00:41 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Tue, 21 May 2019 21:38:56 +0000 (21:38 +0000)
lib/pleroma/object.ex

index 740d687a3505fc03ea0cc2161aa44bba4a5f8872..cc6fc9c5dfeb25c3311778fc4878090069c8dedd 100644 (file)
@@ -130,6 +130,13 @@ defmodule Pleroma.Object do
     end
   end
 
+  def prune(%Object{data: %{"id" => id}} = object) do
+    with {:ok, object} <- Repo.delete(object),
+         {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
+      {:ok, object}
+    end
+  end
+
   def set_cache(%Object{data: %{"id" => ap_id}} = object) do
     Cachex.put(:object_cache, "object:#{ap_id}", object)
     {:ok, object}