Use more efficient queries.
[akkoma] / lib / pleroma / activity.ex
index 46568bb13eb288d6322b145db776e5427aa5e9c8..40e14005b07d4d50ed64ea112c041924058af4a4 100644 (file)
@@ -5,17 +5,24 @@ defmodule Pleroma.Activity do
 
   schema "activities" do
     field :data, :map
+    field :local, :boolean, default: true
 
     timestamps()
   end
 
   def get_by_ap_id(ap_id) do
     Repo.one(from activity in Activity,
-      where: fragment("? @> ?", activity.data, ^%{id: ap_id}))
+      where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)))
   end
 
   def all_by_object_ap_id(ap_id) do
     Repo.all(from activity in Activity,
-      where: fragment("? @> ?", activity.data, ^%{object: %{id: ap_id}}))
+      where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id)))
+  end
+
+  def get_create_activity_by_object_ap_id(ap_id) do
+    Repo.one(from activity in Activity,
+      where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))
+             and fragment("(?)->>'type' = 'Create'", activity.data))
   end
 end