Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into develop
authordtluna <dtluna@openmailbox.org>
Tue, 20 Jun 2017 14:57:04 +0000 (17:57 +0300)
committerdtluna <dtluna@openmailbox.org>
Tue, 20 Jun 2017 14:57:04 +0000 (17:57 +0300)
lib/pleroma/activity.ex
lib/pleroma/web/websub/websub.ex
priv/repo/migrations/20170620133028_add_object_activity_index.exs [new file with mode: 0644]
priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs [new file with mode: 0644]

index d77c8899749a7dd16e568829e3a77340392afa31..40e14005b07d4d50ed64ea112c041924058af4a4 100644 (file)
@@ -12,16 +12,17 @@ defmodule Pleroma.Activity do
 
   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("? @> ?", activity.data, ^%{type: "Create", object: %{id: ap_id}}))
+      where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))
+             and fragment("(?)->>'type' = 'Create'", activity.data))
   end
 end
index a683f6da40de022e443630f8adb279471f019431..12edf094cce4c38b6e46cc6195702e107b7c1157 100644 (file)
@@ -53,10 +53,14 @@ defmodule Pleroma.Web.Websub do
       Logger.debug(fn -> "Pushing to #{sub.callback}" end)
 
       Task.start(fn ->
-        @httpoison.post(sub.callback, response, [
+        with {:ok, %{status_code: code}} <- @httpoison.post(sub.callback, response, [
               {"Content-Type", "application/atom+xml"},
               {"X-Hub-Signature", "sha1=#{signature}"}
-            ])
+                    ]) do
+          Logger.debug(fn -> "Pushed to #{sub.callback}, code #{code}" end)
+        else e ->
+            Logger.debug(fn -> "Couldn't push to #{sub.callback}, #{inspect(e)}" end)
+        end
       end)
     end)
   end
diff --git a/priv/repo/migrations/20170620133028_add_object_activity_index.exs b/priv/repo/migrations/20170620133028_add_object_activity_index.exs
new file mode 100644 (file)
index 0000000..1abbd78
--- /dev/null
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.AddObjectActivityIndex do
+  use Ecto.Migration
+
+  def change do
+    create index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
+  end
+end
diff --git a/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs b/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs
new file mode 100644 (file)
index 0000000..705a05f
--- /dev/null
@@ -0,0 +1,8 @@
+defmodule Pleroma.Repo.Migrations.AddObjectActivityIndexPartTwo do
+  use Ecto.Migration
+
+  def change do
+    drop index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
+    create index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
+  end
+end