From 9af560083fcc513a7b3c41b06f4ed307c50a7529 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 24 Oct 2017 14:16:17 +0200 Subject: [PATCH] Use more efficient user note count update query. --- lib/pleroma/user.ex | 2 +- .../migrations/20171024121413_add_object_actor_index.exs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 priv/repo/migrations/20171024121413_add_object_actor_index.exs 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 @@ def get_friends(%User{id: id, following: following}) 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