Make user timelines faster for users with few statuses.

This commit is contained in:
Roger Braun 2017-07-01 16:43:10 +02:00
parent 9cda5b897a
commit 5e17e04144
3 changed files with 9 additions and 2 deletions

View file

@ -112,7 +112,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_actor(query, %{"actor_id" => actor_id}) do defp restrict_actor(query, %{"actor_id" => actor_id}) do
from activity in query, from activity in query,
where: fragment("? @> ?", activity.data, ^%{actor: actor_id}) where: fragment("?->>'actor' = ?", activity.data, ^actor_id)
end end
defp restrict_actor(query, _), do: query defp restrict_actor(query, _), do: query

View file

@ -19,7 +19,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
def feed(conn, %{"nickname" => nickname}) do def feed(conn, %{"nickname" => nickname}) do
user = User.get_cached_by_nickname(nickname) user = User.get_cached_by_nickname(nickname)
query = from activity in Activity, query = from activity in Activity,
where: fragment("? @> ?", activity.data, ^%{actor: user.ap_id}), where: fragment("?->>'actor' = ?", activity.data, ^user.ap_id),
limit: 20, limit: 20,
order_by: [desc: :inserted_at] order_by: [desc: :inserted_at]

View file

@ -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