Speed up follower query.

This commit is contained in:
lain 2018-03-26 10:31:22 +02:00
parent 1d1271ca1e
commit bd4926288e
2 changed files with 2 additions and 1 deletions

View file

@ -265,7 +265,7 @@ def get_or_fetch_by_nickname(nickname) do
def get_followers(%User{id: id, follower_address: follower_address}) do def get_followers(%User{id: id, follower_address: follower_address}) do
q = from u in User, q = from u in User,
where: ^follower_address in u.following, where: fragment("? <@ ?", ^[follower_address], u.following),
where: u.id != ^id where: u.id != ^id
{:ok, Repo.all(q)} {:ok, Repo.all(q)}

View file

@ -4,5 +4,6 @@ defmodule Pleroma.Repo.Migrations.AddFollowerAddressIndexToUsers do
@disable_ddl_transaction true @disable_ddl_transaction true
def change do def change do
create index(:users, [:follower_address], concurrently: true) create index(:users, [:follower_address], concurrently: true)
create index(:users, [:following], concurrently: true, using: :gin)
end end
end end