forked from AkkomaGang/akkoma
[#3213] Switched to using embedded hashtags in Object.hashtags/1
(to avoid extra joins / preload in timeline queries).
This commit is contained in:
parent
f264d930cc
commit
ea4785213a
2 changed files with 5 additions and 14 deletions
|
@ -98,7 +98,6 @@ def restrict_unauthenticated_access?(resource, kind) do
|
||||||
|
|
||||||
def improved_hashtag_timeline_path, do: [:instance, :improved_hashtag_timeline]
|
def improved_hashtag_timeline_path, do: [:instance, :improved_hashtag_timeline]
|
||||||
def improved_hashtag_timeline, do: get(improved_hashtag_timeline_path())
|
def improved_hashtag_timeline, do: get(improved_hashtag_timeline_path())
|
||||||
def object_embedded_hashtags?, do: !improved_hashtag_timeline()
|
|
||||||
|
|
||||||
def oauth_consumer_strategies, do: get([:auth, :oauth_consumer_strategies], [])
|
def oauth_consumer_strategies, do: get([:auth, :oauth_consumer_strategies], [])
|
||||||
|
|
||||||
|
|
|
@ -388,24 +388,16 @@ def tags(%Object{data: %{"tag" => tags}}) when is_list(tags), do: tags
|
||||||
def tags(_), do: []
|
def tags(_), do: []
|
||||||
|
|
||||||
def hashtags(%Object{} = object) do
|
def hashtags(%Object{} = object) do
|
||||||
cond do
|
# Note: always using embedded hashtags regardless whether they are migrated to hashtags table
|
||||||
Config.object_embedded_hashtags?() ->
|
# (embedded hashtags stay in sync anyways, and we avoid extra joins and preload hassle)
|
||||||
embedded_hashtags(object)
|
embedded_hashtags(object)
|
||||||
|
|
||||||
object.id == "pleroma:fake_object_id" ->
|
|
||||||
[]
|
|
||||||
|
|
||||||
true ->
|
|
||||||
hashtag_records = Repo.preload(object, :hashtags).hashtags
|
|
||||||
Enum.map(hashtag_records, & &1.name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp embedded_hashtags(%Object{data: data}) do
|
def embedded_hashtags(%Object{data: data}) do
|
||||||
object_data_hashtags(data)
|
object_data_hashtags(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp embedded_hashtags(_), do: []
|
def embedded_hashtags(_), do: []
|
||||||
|
|
||||||
def object_data_hashtags(%{"tag" => tags}) when is_list(tags) do
|
def object_data_hashtags(%{"tag" => tags}) when is_list(tags) do
|
||||||
tags
|
tags
|
||||||
|
|
Loading…
Reference in a new issue