Use more efficient queries.

This commit is contained in:
Roger Braun 2017-06-20 16:18:42 +02:00
parent 14a9dd468b
commit 9cf38d6796
2 changed files with 10 additions and 2 deletions

View File

@ -17,11 +17,12 @@ def get_by_ap_id(ap_id) do
def all_by_object_ap_id(ap_id) do def all_by_object_ap_id(ap_id) do
Repo.all(from activity in Activity, 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 end
def get_create_activity_by_object_ap_id(ap_id) do def get_create_activity_by_object_ap_id(ap_id) do
Repo.one(from activity in Activity, 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
end end

View File

@ -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