From 5e17e0414412a951ffc549db9231759292d55bc1 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 1 Jul 2017 16:43:10 +0200 Subject: [PATCH] Make user timelines faster for users with few statuses. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/ostatus/ostatus_controller.ex | 2 +- .../20170701142005_add_actor_index_to_activity.exs | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20170701142005_add_actor_index_to_activity.exs diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 79c1d5b69..69a2d8f4e 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -112,7 +112,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_actor(query, %{"actor_id" => actor_id}) do from activity in query, - where: fragment("? @> ?", activity.data, ^%{actor: actor_id}) + where: fragment("?->>'actor' = ?", activity.data, ^actor_id) end defp restrict_actor(query, _), do: query diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index e676a60c3..05acfd04b 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -19,7 +19,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do def feed(conn, %{"nickname" => nickname}) do user = User.get_cached_by_nickname(nickname) query = from activity in Activity, - where: fragment("? @> ?", activity.data, ^%{actor: user.ap_id}), + where: fragment("?->>'actor' = ?", activity.data, ^user.ap_id), limit: 20, order_by: [desc: :inserted_at] diff --git a/priv/repo/migrations/20170701142005_add_actor_index_to_activity.exs b/priv/repo/migrations/20170701142005_add_actor_index_to_activity.exs new file mode 100644 index 000000000..82c64396f --- /dev/null +++ b/priv/repo/migrations/20170701142005_add_actor_index_to_activity.exs @@ -0,0 +1,7 @@ +defmodule Pleroma.Repo.Migrations.AddActorIndexToActivity do + use Ecto.Migration + + def change do + create index(:activities, ["(data->>'actor')", "inserted_at desc"], name: :activities_actor_index) + end +end