summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2021-02-23 13:52:28 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2021-02-23 13:52:28 +0300
commit77f3da035894e2add911101466bfe41b99ee481e (patch)
tree91196f4fa98d9be3dbd708e23009eb0a0f599c27 /lib
parenta98c4423f374c6be8202ae884989e708e7d8ca3b (diff)
downloadpleroma-77f3da035894e2add911101466bfe41b99ee481e.tar.gz
pleroma-77f3da035894e2add911101466bfe41b99ee481e.zip
[#3213] Misc. tweaks: proper upsert in Hashtag, better feature toggle management.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/config.ex4
-rw-r--r--lib/pleroma/hashtag.ex22
-rw-r--r--lib/pleroma/migrators/hashtags_table_migrator.ex18
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex2
4 files changed, 21 insertions, 25 deletions
diff --git a/lib/pleroma/config.ex b/lib/pleroma/config.ex
index f17e14128..e057d8c02 100644
--- a/lib/pleroma/config.ex
+++ b/lib/pleroma/config.ex
@@ -111,4 +111,8 @@ defmodule Pleroma.Config do
end
)
end
+
+ def feature_enabled?(feature_name) do
+ get([:features, feature_name]) not in [nil, false, :disabled, :auto]
+ end
end
diff --git a/lib/pleroma/hashtag.ex b/lib/pleroma/hashtag.ex
index e9d143fb1..53e2e9c89 100644
--- a/lib/pleroma/hashtag.ex
+++ b/lib/pleroma/hashtag.ex
@@ -27,19 +27,15 @@ defmodule Pleroma.Hashtag do
|> 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
diff --git a/lib/pleroma/migrators/hashtags_table_migrator.ex b/lib/pleroma/migrators/hashtags_table_migrator.ex
index 07bb9aeb2..6123c88e0 100644
--- a/lib/pleroma/migrators/hashtags_table_migrator.ex
+++ b/lib/pleroma/migrators/hashtags_table_migrator.ex
@@ -24,7 +24,7 @@ defmodule Pleroma.Migrators.HashtagsTableMigrator 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)
@@ -296,16 +296,12 @@ defmodule Pleroma.Migrators.HashtagsTableMigrator do
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
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 8182bc205..9d557c2cd 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -1273,7 +1273,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|> 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)