config :pleroma, :database, rum_enabled: false
+config :pleroma, :features, improved_hashtag_timeline: :auto
+
config :pleroma, :populate_hashtags_table, fault_rate_allowance: 0.01
config :pleroma, :env, Mix.env()
},
%{
group: :pleroma,
- key: :database,
+ key: :features,
type: :group,
- description: "Database-related settings",
+ description: "Customizable features",
children: [
%{
key: :improved_hashtag_timeline,
- type: :keyword,
+ type: {:dropdown, :atom},
description:
- "If `true`, hashtags will be fetched from `hashtags` table for hashtags timeline. When `false`, object-embedded hashtags will be used (slower). Is auto-set to `true` (unless overridden) when HashtagsTableMigrator completes."
+ "Setting to force toggle / force disable improved hashtags timeline. `:enabled` forces hashtags to be fetched from `hashtags` table for hashtags timeline. `:disabled` forces object-embedded hashtags to be used (slower). Keep it `:auto` for automatic behaviour (it is auto-set to `:enabled` [unless overridden] when HashtagsTableMigrator completes).",
+ suggestions: [:auto, :enabled, :disabled]
}
]
},
* `password_reset_token_validity`: The time after which reset tokens aren't accepted anymore, in seconds (default: one day).
## :database
-* `improved_hashtag_timeline`: If `true`, hashtags will be fetched from `hashtags` table for hashtags timeline. When `false`, object-embedded hashtags will be used (slower). Is auto-set to `true` (unless overridden) when `HashtagsTableMigrator` completes.
+* `improved_hashtag_timeline`: Setting to force toggle / force disable improved hashtags timeline. `:enabled` forces hashtags to be fetched from `hashtags` table for hashtags timeline. `:disabled` forces object-embedded hashtags to be used (slower). Keep it `:auto` for automatic behaviour (it is auto-set to `:enabled` [unless overridden] when HashtagsTableMigrator completes).
## Background migrations
* `populate_hashtags_table/sleep_interval_ms`: Sleep interval between each chunk of processed records in order to decrease the load on the system (defaults to 0 and should be keep default on most instances).
end
)
end
+
+ def feature_enabled?(feature_name) do
+ get([:features, feature_name]) not in [nil, false, :disabled, :auto]
+ end
end
|> String.trim()
end
- def get_by_name(name) do
- Repo.get_by(Hashtag, name: normalize_name(name))
- end
-
- def get_or_create_by_name(name) when is_bitstring(name) do
- with %Hashtag{} = hashtag <- get_by_name(name) do
- {:ok, hashtag}
- else
- _ ->
- %Hashtag{}
- |> changeset(%{name: name})
- |> Repo.insert()
- end
+ def get_or_create_by_name(name) do
+ changeset = changeset(%Hashtag{}, %{name: name})
+
+ Repo.insert(
+ changeset,
+ on_conflict: [set: [name: get_field(changeset, :name)]],
+ conflict_target: :name,
+ returning: true
+ )
end
def get_or_create_by_names(names) when is_list(names) do
defdelegate put_stat(key, value), to: State, as: :put_data_key
defdelegate increment_stat(key, increment), to: State, as: :increment_data_key
- @feature_config_path [:database, :improved_hashtag_timeline]
+ @feature_config_path [:features, :improved_hashtag_timeline]
@reg_name {:global, __MODULE__}
def whereis, do: GenServer.whereis(@reg_name)
end
defp on_complete(data_migration) do
- cond do
- data_migration.feature_lock ->
- :noop
-
- not is_nil(feature_state()) ->
- :noop
-
- true ->
- Config.put(@feature_config_path, true)
- :ok
+ if data_migration.feature_lock || feature_state() == :disabled do
+ Logger.warn("#{__MODULE__}: migration complete but feature is locked; consider enabling.")
+ :noop
+ else
+ Config.put(@feature_config_path, :enabled)
+ :ok
end
end
|> exclude_invisible_actors(opts)
|> exclude_visibility(opts)
- if Config.get([:database, :improved_hashtag_timeline]) do
+ if Config.feature_enabled?(:improved_hashtag_timeline) do
query
|> restrict_hashtag_any(opts)
|> restrict_hashtag_all(opts)
{:ok, status_four} = CommonAPI.post(user, %{status: ". #Any1 #any2"})
{:ok, status_five} = CommonAPI.post(user, %{status: ". #Any2 #any1"})
- for hashtag_timeline_strategy <- [true, false] do
- clear_config([:database, :improved_hashtag_timeline], hashtag_timeline_strategy)
+ for hashtag_timeline_strategy <- [:eanbled, :disabled] do
+ clear_config([:features, :improved_hashtag_timeline], hashtag_timeline_strategy)
fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"})