From fe27b61a726ecf328a58ecab1f31434770dfd748 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 20 Jun 2017 14:10:44 +0200 Subject: [PATCH 1/4] Add some debugging to federations. --- lib/pleroma/web/websub/websub.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index a683f6da4..12edf094c 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -53,10 +53,14 @@ defmodule Pleroma.Web.Websub do Logger.debug(fn -> "Pushing to #{sub.callback}" end) Task.start(fn -> - @httpoison.post(sub.callback, response, [ + with {:ok, %{status_code: code}} <- @httpoison.post(sub.callback, response, [ {"Content-Type", "application/atom+xml"}, {"X-Hub-Signature", "sha1=#{signature}"} - ]) + ]) do + Logger.debug(fn -> "Pushed to #{sub.callback}, code #{code}" end) + else e -> + Logger.debug(fn -> "Couldn't push to #{sub.callback}, #{inspect(e)}" end) + end end) end) end From 14a9dd468b1f445fa0fb49ab222d51eaa0e98faf Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 20 Jun 2017 16:02:17 +0200 Subject: [PATCH 2/4] Use more efficient query. --- lib/pleroma/activity.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index d77c88997..f48199cae 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -12,7 +12,7 @@ defmodule Pleroma.Activity do def get_by_ap_id(ap_id) do Repo.one(from activity in Activity, - where: fragment("? @> ?", activity.data, ^%{id: ap_id})) + where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id))) end def all_by_object_ap_id(ap_id) do From 9cf38d679671181cf539883981f92e6777beb951 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 20 Jun 2017 16:18:42 +0200 Subject: [PATCH 3/4] Use more efficient queries. --- lib/pleroma/activity.ex | 5 +++-- .../20170620133028_add_object_activity_index.exs | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20170620133028_add_object_activity_index.exs diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index f48199cae..40e14005b 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -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 diff --git a/priv/repo/migrations/20170620133028_add_object_activity_index.exs b/priv/repo/migrations/20170620133028_add_object_activity_index.exs new file mode 100644 index 000000000..1abbd7802 --- /dev/null +++ b/priv/repo/migrations/20170620133028_add_object_activity_index.exs @@ -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 From 07cee92cd4a28d4863dab6c8ccfd4cbfdd49b42a Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 20 Jun 2017 16:25:28 +0200 Subject: [PATCH 4/4] Add correct index. --- .../20170620142420_add_object_activity_index_part_two.exs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs diff --git a/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs b/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs new file mode 100644 index 000000000..705a05f82 --- /dev/null +++ b/priv/repo/migrations/20170620142420_add_object_activity_index_part_two.exs @@ -0,0 +1,8 @@ +defmodule Pleroma.Repo.Migrations.AddObjectActivityIndexPartTwo do + use Ecto.Migration + + def change do + drop index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index) + create index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index) + end +end