Use more efficient user note count update query.
authorRoger Braun <rbraun@Bobble.local>
Tue, 24 Oct 2017 12:16:17 +0000 (14:16 +0200)
committerRoger Braun <rbraun@Bobble.local>
Tue, 24 Oct 2017 12:16:17 +0000 (14:16 +0200)
lib/pleroma/user.ex
priv/repo/migrations/20171024121413_add_object_actor_index.exs [new file with mode: 0644]

index 938b57d90c47322e754e02704cc8c459519e4edd..bfd3a3ad7aa3a5890d10506b7011faa903fec057 100644 (file)
@@ -241,7 +241,7 @@ defmodule Pleroma.User do
 
   def update_note_count(%User{} = user) do
     note_count_query = from a in Object,
-      where: fragment("? @> ?", a.data, ^%{actor: user.ap_id, type: "Note"}),
+      where: fragment("?->>'actor' = ? and ?->>'type' = 'Note'", a.data, ^user.ap_id, a.data),
       select: count(a.id)
 
     note_count = Repo.one(note_count_query)
diff --git a/priv/repo/migrations/20171024121413_add_object_actor_index.exs b/priv/repo/migrations/20171024121413_add_object_actor_index.exs
new file mode 100644 (file)
index 0000000..344c9c8
--- /dev/null
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddObjectActorIndex do
+  use Ecto.Migration
+
+  @disable_ddl_transaction true
+
+  def change do
+    create index(:objects, ["(data->>'actor')", "(data->>'type')"], concurrently: true, name: :objects_actor_type)
+  end
+end