Commit 9f417fd5 authored by Roger Braun's avatar Roger Braun
Browse files

Speed up deletion and related queries.

parent 5912dd0f
......@@ -16,17 +16,22 @@ def get_by_ap_id(ap_id) do
where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)))
end
# TODO:
# Go through these and fix them everywhere.
# Wrong name, only returns create activities
def all_by_object_ap_id_q(ap_id) do
from activity in Activity,
where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))
where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)),
where: fragment("(?)->>'type' = 'Create'", activity.data)
end
# Wrong name, returns all.
def all_non_create_by_object_ap_id_q(ap_id) do
from activity in Activity,
where: fragment("(?)->>'object' = ?", activity.data, ^to_string(ap_id))
where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id))
end
# Wrong name plz fix thx
def all_by_object_ap_id(ap_id) do
Repo.all(all_by_object_ap_id_q(ap_id))
end
......
......@@ -87,7 +87,6 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru
}
with Repo.delete(object),
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
Repo.delete_all(Activity.all_by_object_ap_id_q(id)),
{:ok, activity} <- insert(data, local),
:ok <- maybe_federate(activity) do
{:ok, activity}
......
defmodule Pleroma.Repo.Migrations.AddSecondObjectIndexToActivty do
use Ecto.Migration
@disable_ddl_transaction true
def change do
drop_if_exists index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
create index(:activities, ["(coalesce(data->'object'->>'id', data->>'object'))"], name: :activities_create_objects_index, concurrently: true)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment