Massage index until it actually does the stuff we want.
authorlain <lain@soykaf.club>
Mon, 4 Feb 2019 22:47:29 +0000 (23:47 +0100)
committerlain <lain@soykaf.club>
Mon, 4 Feb 2019 22:47:29 +0000 (23:47 +0100)
Also makes the index a lot smoler.

lib/pleroma/web/activity_pub/activity_pub.ex
priv/repo/migrations/20190204200237_add_correct_dm_index.exs [new file with mode: 0644]

index 4635e7fcd674a438a632d7b9dc1ab4c0bc51c196..b33912721782fb05cfbf3f32ee0fed3b7f2412b8 100644 (file)
@@ -521,7 +521,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   defp restrict_actor(query, _), do: query
 
   defp restrict_type(query, %{"type" => type}) when is_binary(type) do
-    restrict_type(query, %{"type" => [type]})
+    from(activity in query, where: fragment("?->>'type' = ?", activity.data, ^type))
   end
 
   defp restrict_type(query, %{"type" => type}) do
diff --git a/priv/repo/migrations/20190204200237_add_correct_dm_index.exs b/priv/repo/migrations/20190204200237_add_correct_dm_index.exs
new file mode 100644 (file)
index 0000000..558732c
--- /dev/null
@@ -0,0 +1,30 @@
+defmodule Pleroma.Repo.Migrations.AddCorrectDMIndex do
+  use Ecto.Migration
+  @disable_ddl_transaction true
+
+  def up do
+    drop_if_exists(
+      index(:activities, ["activity_visibility(actor, recipients, data)"],
+        name: :activities_visibility_index
+      )
+    )
+
+    create(
+      index(:activities, ["activity_visibility(actor, recipients, data)", "id DESC NULLS LAST"],
+        name: :activities_visibility_index,
+        concurrently: true,
+        where: "data->>'type' = 'Create'"
+      )
+    )
+  end
+
+  def down do
+    drop(
+      index(:activities, ["activity_visibility(actor, recipients, data)", "id DESC"],
+        name: :activities_visibility_index,
+        concurrently: true,
+        where: "data->>'type' = 'Create'"
+      )
+    )
+  end
+end