From: Roger Braun Date: Tue, 24 Oct 2017 12:16:17 +0000 (+0200) Subject: Use more efficient user note count update query. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=9af560083fcc513a7b3c41b06f4ed307c50a7529;p=akkoma Use more efficient user note count update query. --- diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 938b57d90..bfd3a3ad7 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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 index 000000000..344c9c825 --- /dev/null +++ b/priv/repo/migrations/20171024121413_add_object_actor_index.exs @@ -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