forked from AkkomaGang/akkoma
Merge branch 'get-context-optimizations' into 'develop'
Preload thread mutes/bookmarks in get_context See merge request pleroma/pleroma!1562
This commit is contained in:
commit
fe42844bda
2 changed files with 11 additions and 5 deletions
|
@ -518,6 +518,8 @@ defp fetch_activities_for_context_query(context, opts) do
|
||||||
|
|
||||||
from(activity in Activity)
|
from(activity in Activity)
|
||||||
|> maybe_preload_objects(opts)
|
|> maybe_preload_objects(opts)
|
||||||
|
|> maybe_preload_bookmarks(opts)
|
||||||
|
|> maybe_set_thread_muted_field(opts)
|
||||||
|> restrict_blocked(opts)
|
|> restrict_blocked(opts)
|
||||||
|> restrict_recipients(recipients, opts["user"])
|
|> restrict_recipients(recipients, opts["user"])
|
||||||
|> where(
|
|> where(
|
||||||
|
@ -531,6 +533,7 @@ defp fetch_activities_for_context_query(context, opts) do
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|> exclude_poll_votes(opts)
|
|> exclude_poll_votes(opts)
|
||||||
|
|> exclude_id(opts)
|
||||||
|> order_by([activity], desc: activity.id)
|
|> order_by([activity], desc: activity.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -870,6 +873,12 @@ defp exclude_poll_votes(query, _) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp exclude_id(query, %{"exclude_id" => id}) when is_binary(id) do
|
||||||
|
from(activity in query, where: activity.id != ^id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp exclude_id(query, _), do: query
|
||||||
|
|
||||||
defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query
|
defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query
|
||||||
|
|
||||||
defp maybe_preload_objects(query, _) do
|
defp maybe_preload_objects(query, _) do
|
||||||
|
|
|
@ -497,12 +497,9 @@ def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
activities <-
|
activities <-
|
||||||
ActivityPub.fetch_activities_for_context(activity.data["context"], %{
|
ActivityPub.fetch_activities_for_context(activity.data["context"], %{
|
||||||
"blocking_user" => user,
|
"blocking_user" => user,
|
||||||
"user" => user
|
"user" => user,
|
||||||
|
"exclude_id" => activity.id
|
||||||
}),
|
}),
|
||||||
activities <-
|
|
||||||
activities |> Enum.filter(fn %{id: aid} -> to_string(aid) != to_string(id) end),
|
|
||||||
activities <-
|
|
||||||
activities |> Enum.filter(fn %{data: %{"type" => type}} -> type == "Create" end),
|
|
||||||
grouped_activities <- Enum.group_by(activities, fn %{id: id} -> id < activity.id end) do
|
grouped_activities <- Enum.group_by(activities, fn %{id: id} -> id < activity.id end) do
|
||||||
result = %{
|
result = %{
|
||||||
ancestors:
|
ancestors:
|
||||||
|
|
Loading…
Reference in a new issue