Speed up instance timeline query

This commit is contained in:
Alex Gleason 2020-08-05 13:08:13 -05:00
parent afa8b469ed
commit ad9c925efb
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 6 additions and 3 deletions

View file

@ -928,7 +928,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_muted_reblogs(query, _), do: query defp restrict_muted_reblogs(query, _), do: query
defp restrict_instance(query, %{instance: instance}) when is_binary(instance) do defp restrict_instance(query, %{instance: instance}) when is_binary(instance) do
from(activity in query, where: ilike(activity.actor, ^"%://#{instance}/%")) from(
activity in query,
where: fragment("split_part(actor::text, '/'::text, 3) = ?", ^instance)
)
end end
defp restrict_instance(query, _), do: query defp restrict_instance(query, _), do: query

View file

@ -1647,8 +1647,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "instances" do describe "instances" do
test "GET /instances/:instance/statuses", %{conn: conn} do test "GET /instances/:instance/statuses", %{conn: conn} do
user = insert(:user, local: false, nickname: "archaeme@archae.me") user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme")
user2 = insert(:user, local: false, nickname: "test@test.com") user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")
insert_pair(:note_activity, user: user) insert_pair(:note_activity, user: user)
activity = insert(:note_activity, user: user2) activity = insert(:note_activity, user: user2)