Skip to content
Snippets Groups Projects
Commit 9cf38d67 authored by lain's avatar lain
Browse files

Use more efficient queries.

parent 14a9dd46
No related branches found
No related tags found
No related merge requests found
......@@ -17,11 +17,12 @@ defmodule Pleroma.Activity do
def all_by_object_ap_id(ap_id) do
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
def get_create_activity_by_object_ap_id(ap_id) do
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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment