mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-23 06:58:58 +00:00
Make use of the indices.
Indices in postgresql rely on operators, so they won't be used if you use only functions.
This commit is contained in:
parent
79e44042bc
commit
b108aeee08
|
@ -734,7 +734,16 @@ defmodule Pleroma.User do
|
|||
^processed_query
|
||||
)
|
||||
},
|
||||
where: not is_nil(u.nickname)
|
||||
where:
|
||||
fragment(
|
||||
"""
|
||||
(setweight(to_tsvector('simple', regexp_replace(?, '\\W', ' ', 'g')), 'A') ||
|
||||
setweight(to_tsvector('simple', regexp_replace(coalesce(?, ''), '\\W', ' ', 'g')), 'B')) @@ to_tsquery('simple', ?)
|
||||
""",
|
||||
u.nickname,
|
||||
u.name,
|
||||
^processed_query
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -750,7 +759,7 @@ defmodule Pleroma.User do
|
|||
u.name
|
||||
)
|
||||
},
|
||||
where: not is_nil(u.nickname)
|
||||
where: fragment("trim(? || ' ' || coalesce(?, '')) % ?", u.nickname, u.name, ^query)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,12 +2,21 @@ defmodule Pleroma.Repo.Migrations.FixUserTrigramIndex do
|
|||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
drop_if_exists index(:users, [], name: :users_trigram_index)
|
||||
create index(:users, ["(trim(nickname || ' ' || name)) gist_trgm_ops"], name: :users_trigram_index, using: :gist)
|
||||
drop_if_exists(index(:users, [], name: :users_trigram_index))
|
||||
|
||||
create(
|
||||
index(:users, ["(trim(nickname || ' ' || coalesce(name, ''))) gist_trgm_ops"],
|
||||
name: :users_trigram_index,
|
||||
using: :gist
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def down do
|
||||
drop_if_exists index(:users, [], name: :users_trigram_index)
|
||||
create index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist)
|
||||
drop_if_exists(index(:users, [], name: :users_trigram_index))
|
||||
|
||||
create(
|
||||
index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue