aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/activity/search.ex36
-rw-r--r--lib/pleroma/application.ex23
-rw-r--r--lib/pleroma/config/holder.ex19
-rw-r--r--lib/pleroma/config/release_runtime_provider.ex50
4 files changed, 118 insertions, 10 deletions
diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex
index 382c81118..babf9520b 100644
--- a/lib/pleroma/activity/search.ex
+++ b/lib/pleroma/activity/search.ex
@@ -19,11 +19,18 @@ defmodule Pleroma.Activity.Search do
offset = Keyword.get(options, :offset, 0)
author = Keyword.get(options, :author)
+ search_function =
+ if :persistent_term.get({Pleroma.Repo, :postgres_version}) >= 11 do
+ :websearch
+ else
+ :plain
+ end
+
Activity
|> Activity.with_preloaded_object()
|> Activity.restrict_deactivated_users()
|> restrict_public()
- |> query_with(index_type, search_query)
+ |> query_with(index_type, search_query, search_function)
|> maybe_restrict_local(user)
|> maybe_restrict_author(author)
|> maybe_restrict_blocked(user)
@@ -53,7 +60,7 @@ defmodule Pleroma.Activity.Search do
)
end
- defp query_with(q, :gin, search_query) do
+ defp query_with(q, :gin, search_query, :plain) do
from([a, o] in q,
where:
fragment(
@@ -64,7 +71,18 @@ defmodule Pleroma.Activity.Search do
)
end
- defp query_with(q, :rum, search_query) do
+ defp query_with(q, :gin, search_query, :websearch) do
+ from([a, o] in q,
+ where:
+ fragment(
+ "to_tsvector('english', ?->>'content') @@ websearch_to_tsquery('english', ?)",
+ o.data,
+ ^search_query
+ )
+ )
+ end
+
+ defp query_with(q, :rum, search_query, :plain) do
from([a, o] in q,
where:
fragment(
@@ -76,6 +94,18 @@ defmodule Pleroma.Activity.Search do
)
end
+ defp query_with(q, :rum, search_query, :websearch) do
+ from([a, o] in q,
+ where:
+ fragment(
+ "? @@ websearch_to_tsquery('english', ?)",
+ o.fts_content,
+ ^search_query
+ ),
+ order_by: [fragment("? <=> now()::date", o.inserted_at)]
+ )
+ end
+
defp maybe_restrict_local(q, user) do
limit = Pleroma.Config.get([:instance, :limit_to_local_content], :unauthenticated)
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex
index ced14f87f..bd568d858 100644
--- a/lib/pleroma/application.ex
+++ b/lib/pleroma/application.ex
@@ -110,7 +110,28 @@ defmodule Pleroma.Application do
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
- Supervisor.start_link(children, opts)
+ result = 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.warn(
+ "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
def load_custom_modules do
diff --git a/lib/pleroma/config/holder.ex b/lib/pleroma/config/holder.ex
index f037d5d48..a99fc0471 100644
--- a/lib/pleroma/config/holder.ex
+++ b/lib/pleroma/config/holder.ex
@@ -9,12 +9,7 @@ defmodule Pleroma.Config.Holder do
def save_default do
default_config =
if System.get_env("RELEASE_NAME") do
- release_config =
- [:code.root_dir(), "releases", System.get_env("RELEASE_VSN"), "releases.exs"]
- |> Path.join()
- |> Pleroma.Config.Loader.read()
-
- Pleroma.Config.Loader.merge(@config, release_config)
+ Pleroma.Config.Loader.merge(@config, release_defaults())
else
@config
end
@@ -32,4 +27,16 @@ defmodule Pleroma.Config.Holder do
def default_config(group, key), do: get_in(get_default(), [group, key])
defp get_default, do: Pleroma.Config.get(:default_config)
+
+ @spec release_defaults() :: keyword()
+ def release_defaults do
+ [
+ pleroma: [
+ {:instance, [static_dir: "/var/lib/pleroma/static"]},
+ {Pleroma.Uploaders.Local, [uploads: "/var/lib/pleroma/uploads"]},
+ {:modules, [runtime_dir: "/var/lib/pleroma/modules"]},
+ {:release, true}
+ ]
+ ]
+ end
end
diff --git a/lib/pleroma/config/release_runtime_provider.ex b/lib/pleroma/config/release_runtime_provider.ex
new file mode 100644
index 000000000..8227195dc
--- /dev/null
+++ b/lib/pleroma/config/release_runtime_provider.ex
@@ -0,0 +1,50 @@
+defmodule Pleroma.Config.ReleaseRuntimeProvider do
+ @moduledoc """
+ Imports `runtime.exs` and `{env}.exported_from_db.secret.exs` for elixir releases.
+ """
+ @behaviour Config.Provider
+
+ @impl true
+ def init(opts), do: opts
+
+ @impl true
+ def load(config, _opts) do
+ with_defaults = Config.Reader.merge(config, Pleroma.Config.Holder.release_defaults())
+
+ config_path = System.get_env("PLEROMA_CONFIG_PATH") || "/etc/pleroma/config.exs"
+
+ with_runtime_config =
+ if File.exists?(config_path) do
+ runtime_config = Config.Reader.read!(config_path)
+
+ with_defaults
+ |> Config.Reader.merge(pleroma: [config_path: config_path])
+ |> Config.Reader.merge(runtime_config)
+ else
+ warning = [
+ IO.ANSI.red(),
+ IO.ANSI.bright(),
+ "!!! #{config_path} not found! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file",
+ IO.ANSI.reset()
+ ]
+
+ IO.puts(warning)
+ with_defaults
+ end
+
+ exported_config_path =
+ config_path
+ |> Path.dirname()
+ |> Path.join("prod.exported_from_db.secret.exs")
+
+ with_exported =
+ if File.exists?(exported_config_path) do
+ exported_config = Config.Reader.read!(with_runtime_config)
+ Config.Reader.merge(with_runtime_config, exported_config)
+ else
+ with_runtime_config
+ end
+
+ with_exported
+ end
+end