aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Braun <rbraun@Bobble.local>2017-10-23 18:30:09 +0200
committerRoger Braun <rbraun@Bobble.local>2017-10-23 18:30:09 +0200
commit9f417fd5e9893b095041702a6bd0190c7f1d7f22 (patch)
treedf87e159d5b6e49475909f75f8334c80c3f37f15
parent5912dd0f5dfaecc3732d2174867490c5a6b88c11 (diff)
downloadpleroma-9f417fd5e9893b095041702a6bd0190c7f1d7f22.tar.gz
Speed up deletion and related queries.
-rw-r--r--lib/pleroma/activity.ex9
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex1
-rw-r--r--priv/repo/migrations/20171023155035_add_second_object_index_to_activty.exs10
3 files changed, 17 insertions, 3 deletions
diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex
index 9a5e6fc78..d7e31b6b4 100644
--- a/lib/pleroma/activity.ex
+++ b/lib/pleroma/activity.ex
@@ -16,17 +16,22 @@ defmodule Pleroma.Activity 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
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 31aa2c4f1..dcd27d04a 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -87,7 +87,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
}
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}
diff --git a/priv/repo/migrations/20171023155035_add_second_object_index_to_activty.exs b/priv/repo/migrations/20171023155035_add_second_object_index_to_activty.exs
new file mode 100644
index 000000000..c6df53ec9
--- /dev/null
+++ b/priv/repo/migrations/20171023155035_add_second_object_index_to_activty.exs
@@ -0,0 +1,10 @@
+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