From bd4926288e6b5d8d3e4439d83e30fa0211045d0b Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 26 Mar 2018 10:31:22 +0200 Subject: [PATCH] Speed up follower query. --- lib/pleroma/user.ex | 2 +- .../migrations/20180325172351_add_follower_address_index_to_users.exs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index e92b85f52..0594afb38 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -265,7 +265,7 @@ defmodule Pleroma.User do def get_followers(%User{id: id, follower_address: follower_address}) do q = from u in User, - where: ^follower_address in u.following, + where: fragment("? <@ ?", ^[follower_address], u.following), where: u.id != ^id {:ok, Repo.all(q)} diff --git a/priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs b/priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs index dbf9599b0..234d33735 100644 --- a/priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs +++ b/priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs @@ -4,5 +4,6 @@ defmodule Pleroma.Repo.Migrations.AddFollowerAddressIndexToUsers do @disable_ddl_transaction true def change do create index(:users, [:follower_address], concurrently: true) + create index(:users, [:following], concurrently: true, using: :gin) end end