Handle incoming favorites, fetch potentially missing messages.
[akkoma] / lib / pleroma / object.ex
index a924c3199d53698cdaf247e3181b920f62313129..949ccb0f66e172a6b4bece0983e55ef20fa52b8d 100644 (file)
@@ -14,6 +14,22 @@ defmodule Pleroma.Object do
       where: fragment("? @> ?", object.data, ^%{id: ap_id}))
   end
 
+  def get_cached_by_ap_id(ap_id) do
+    if Mix.env == :test do
+      get_by_ap_id(ap_id)
+    else
+      key = "object:#{ap_id}"
+      Cachex.get!(:user_cache, key, fallback: fn(_) ->
+        object = get_by_ap_id(ap_id)
+        if object do
+          {:commit, object}
+        else
+          {:ignore, object}
+        end
+      end)
+    end
+  end
+
   def context_mapping(context) do
     %Object{data: %{"id" => context}}
   end