Merge branch 'postgres-bump' into 'develop'

Update minimum Postgres version to 11.0; disable JIT

See merge request pleroma/pleroma!4093
This commit is contained in:
lain 2024-03-19 04:46:40 +00:00
commit ca5766c0a7
9 changed files with 20 additions and 68 deletions

View file

@ -113,7 +113,7 @@ benchmark:
variables: variables:
MIX_ENV: benchmark MIX_ENV: benchmark
services: services:
- name: postgres:9.6-alpine - name: postgres:11.22-alpine
alias: postgres alias: postgres
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"] command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
script: script:

View file

@ -0,0 +1 @@
Disable jit by default for PostgreSQL

View file

@ -799,7 +799,7 @@ config :pleroma, :modules, runtime_dir: "instance/modules"
config :pleroma, configurable_from_database: false config :pleroma, configurable_from_database: false
config :pleroma, Pleroma.Repo, config :pleroma, Pleroma.Repo,
parameters: [gin_fuzzy_search_limit: "500"], parameters: [gin_fuzzy_search_limit: "500", jit: "off"],
prepare: :unnamed prepare: :unnamed
config :pleroma, :connections_pool, config :pleroma, :connections_pool,

View file

@ -12,8 +12,8 @@ Note: This article is potentially outdated because at this time we may not have
### 必要なソフトウェア ### 必要なソフトウェア
- PostgreSQL 9.6以上 (Ubuntu16.04では9.5しか提供されていないので,[](https://www.postgresql.org/download/linux/ubuntu/)こちらから新しいバージョンを入手してください) - PostgreSQL 11.0以上 (Ubuntu16.04では9.5しか提供されていないので,[](https://www.postgresql.org/download/linux/ubuntu/)こちらから新しいバージョンを入手してください)
- `postgresql-contrib` 9.6以上 (同上) - `postgresql-contrib` 11.0以上 (同上)
- Elixir 1.8 以上 ([Debianのリポジトリからインストールしないこと ここからインストールすること!](https://elixir-lang.org/install.html#unix-and-unix-like)。または [asdf](https://github.com/asdf-vm/asdf) をpleromaユーザーでインストールしてください) - Elixir 1.8 以上 ([Debianのリポジトリからインストールしないこと ここからインストールすること!](https://elixir-lang.org/install.html#unix-and-unix-like)。または [asdf](https://github.com/asdf-vm/asdf) をpleromaユーザーでインストールしてください)
- `erlang-dev` - `erlang-dev`
- `erlang-nox` - `erlang-nox`

View file

@ -1,6 +1,6 @@
## Required dependencies ## Required dependencies
* PostgreSQL >=9.6 * PostgreSQL >=11.0
* Elixir >=1.11.0 <1.15 * Elixir >=1.11.0 <1.15
* Erlang OTP >=22.2.0 (supported: <27) * Erlang OTP >=22.2.0 (supported: <27)
* git * git

View file

@ -119,28 +119,7 @@ defmodule Pleroma.Application do
max_restarts = Application.get_env(:pleroma, __MODULE__)[:max_restarts] max_restarts = Application.get_env(:pleroma, __MODULE__)[:max_restarts]
opts = [strategy: :one_for_one, name: Pleroma.Supervisor, max_restarts: max_restarts] opts = [strategy: :one_for_one, name: Pleroma.Supervisor, max_restarts: max_restarts]
result = Supervisor.start_link(children, opts) Supervisor.start_link(children, opts)
set_postgres_server_version()
result
end
defp set_postgres_server_version do
version =
with %{rows: [[version]]} <- Ecto.Adapters.SQL.query!(Pleroma.Repo, "show server_version"),
{num, _} <- Float.parse(version) do
num
else
e ->
Logger.warning(
"Could not get the postgres version: #{inspect(e)}.\nSetting the default value of 9.6"
)
9.6
end
:persistent_term.put({Pleroma.Repo, :postgres_version}, version)
end end
def load_custom_modules do def load_custom_modules do

View file

@ -23,19 +23,12 @@ defmodule Pleroma.Search.DatabaseSearch do
offset = Keyword.get(options, :offset, 0) offset = Keyword.get(options, :offset, 0)
author = Keyword.get(options, :author) author = Keyword.get(options, :author)
search_function =
if :persistent_term.get({Pleroma.Repo, :postgres_version}) >= 11 do
:websearch
else
:plain
end
try do try do
Activity Activity
|> Activity.with_preloaded_object() |> Activity.with_preloaded_object()
|> Activity.restrict_deactivated_users() |> Activity.restrict_deactivated_users()
|> restrict_public(user) |> restrict_public(user)
|> query_with(index_type, search_query, search_function) |> query_with(index_type, search_query, :websearch)
|> maybe_restrict_local(user) |> maybe_restrict_local(user)
|> maybe_restrict_author(author) |> maybe_restrict_author(author)
|> maybe_restrict_blocked(user) |> maybe_restrict_blocked(user)

View file

@ -35,21 +35,6 @@ defmodule Pleroma.Search.DatabaseSearchTest do
assert [] = Search.search(nil, "wednesday") assert [] = Search.search(nil, "wednesday")
end end
test "using plainto_tsquery on postgres < 11" do
old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
:persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
user = insert(:user)
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
{:ok, _post2} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
# plainto doesn't understand complex queries
assert [result] = Search.search(nil, "wednesday -dudes")
assert result.id == post.id
end
test "using websearch_to_tsquery" do test "using websearch_to_tsquery" do
user = insert(:user) user = insert(:user)
{:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"}) {:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})

View file

@ -322,26 +322,20 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
end end
test "search fetches remote statuses and prefers them over other results", %{conn: conn} do test "search fetches remote statuses and prefers them over other results", %{conn: conn} do
old_version = :persistent_term.get({Pleroma.Repo, :postgres_version}) {:ok, %{id: activity_id}} =
:persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0) CommonAPI.post(insert(:user), %{
on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end) status: "check out http://mastodon.example.org/@admin/99541947525187367"
})
capture_log(fn -> %{"url" => result_url, "id" => result_id} =
{:ok, %{id: activity_id}} = conn
CommonAPI.post(insert(:user), %{ |> get("/api/v1/search?q=http://mastodon.example.org/@admin/99541947525187367")
status: "check out http://mastodon.example.org/@admin/99541947525187367" |> json_response_and_validate_schema(200)
}) |> Map.get("statuses")
|> List.first()
results = refute match?(^result_id, activity_id)
conn assert match?(^result_url, "http://mastodon.example.org/@admin/99541947525187367")
|> get("/api/v1/search?q=http://mastodon.example.org/@admin/99541947525187367")
|> json_response_and_validate_schema(200)
assert [
%{"url" => "http://mastodon.example.org/@admin/99541947525187367"},
%{"id" => ^activity_id}
] = results["statuses"]
end)
end end
test "search doesn't show statuses that it shouldn't", %{conn: conn} do test "search doesn't show statuses that it shouldn't", %{conn: conn} do