Speed up follower query.
authorlain <lain@soykaf.club>
Mon, 26 Mar 2018 08:31:22 +0000 (10:31 +0200)
committerlain <lain@soykaf.club>
Mon, 26 Mar 2018 08:31:22 +0000 (10:31 +0200)
lib/pleroma/user.ex
priv/repo/migrations/20180325172351_add_follower_address_index_to_users.exs

index e92b85f52c2baea89ecc9c96f4bf8f4064e07d5a..0594afb3809e27a3523c44e851315e34b9399a63 100644 (file)
@@ -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)}
index dbf9599b002210d2598c9237aade2d2baf6d0489..234d33735f18ac4d767f825ba4a56ac5caa2eb00 100644 (file)
@@ -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