fix(search): set gin_fuzzy_search_limit only for search queries
The limit was a connection parameter, so it applied to every GIN index scan, not only full-text search: recipient lookups and Oban job queries could return incomplete, random results. Set it with SET LOCAL around the search query only, configurable under Pleroma.Search.DatabaseSearch. The default stays 500 for search: measured on a 74M-object database, higher limits or none make searches for common words exceed the query timeout. Remote fetches for URL queries run outside the transaction. Based on Akkoma 811f0a468. Co-authored-by: Oneric <oneric@oneric.stub>
This commit is contained in:
parent
24038667b2
commit
fa8541309c
6 changed files with 98 additions and 17 deletions
|
|
@ -44,4 +44,31 @@ defmodule Pleroma.Search.DatabaseSearchTest do
|
|||
|
||||
assert result.id == other_post.id
|
||||
end
|
||||
|
||||
describe "gin_fuzzy_search_limit" do
|
||||
defp fuzzy_limit do
|
||||
%{rows: [[value]]} = Pleroma.Repo.query!("SHOW gin_fuzzy_search_limit")
|
||||
value
|
||||
end
|
||||
|
||||
test "is not set on normal database connections" do
|
||||
assert fuzzy_limit() == "0"
|
||||
end
|
||||
|
||||
test "is only set for the search query when configured" do
|
||||
clear_config([Search, :gin_fuzzy_search_limit], nil)
|
||||
assert Search.with_fuzzy_limit(&fuzzy_limit/0) == "0"
|
||||
|
||||
clear_config([Search, :gin_fuzzy_search_limit], 10_000)
|
||||
assert Search.with_fuzzy_limit(&fuzzy_limit/0) == "10000"
|
||||
end
|
||||
|
||||
test "search still works with a limit" do
|
||||
clear_config([Search, :gin_fuzzy_search_limit], 10_000)
|
||||
{:ok, post} = CommonAPI.post(insert(:user), %{status: "it's wednesday my dudes"})
|
||||
|
||||
assert [%{id: id}] = Search.search(nil, "wednesday")
|
||||
assert id == post.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue