forked from AkkomaGang/akkoma
Merge branch 'fix/oom-parallel-rendering' into 'develop'
Revert "Parallelize template rendering" See merge request pleroma/pleroma!1654
This commit is contained in:
commit
fb7332aec7
3 changed files with 23 additions and 35 deletions
|
@ -27,7 +27,7 @@ def run(["tag"]) do
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["render_timeline", nickname]) do
|
def run(["render_timeline", nickname | _] = args) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
user = Pleroma.User.get_by_nickname(nickname)
|
user = Pleroma.User.get_by_nickname(nickname)
|
||||||
|
|
||||||
|
@ -37,33 +37,37 @@ def run(["render_timeline", nickname]) do
|
||||||
|> Map.put("blocking_user", user)
|
|> Map.put("blocking_user", user)
|
||||||
|> Map.put("muting_user", user)
|
|> Map.put("muting_user", user)
|
||||||
|> Map.put("user", user)
|
|> Map.put("user", user)
|
||||||
|> Map.put("limit", 80)
|
|> Map.put("limit", 4096)
|
||||||
|> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
|
|> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
|
||||||
|> Enum.reverse()
|
|> Enum.reverse()
|
||||||
|
|
||||||
inputs = %{
|
inputs = %{
|
||||||
"One activity" => Enum.take_random(activities, 1),
|
"1 activity" => Enum.take_random(activities, 1),
|
||||||
"Ten activities" => Enum.take_random(activities, 10),
|
"10 activities" => Enum.take_random(activities, 10),
|
||||||
"Twenty activities" => Enum.take_random(activities, 20),
|
"20 activities" => Enum.take_random(activities, 20),
|
||||||
"Forty activities" => Enum.take_random(activities, 40),
|
"40 activities" => Enum.take_random(activities, 40),
|
||||||
"Eighty activities" => Enum.take_random(activities, 80)
|
"80 activities" => Enum.take_random(activities, 80)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inputs =
|
||||||
|
if Enum.at(args, 2) == "extended" do
|
||||||
|
Map.merge(inputs, %{
|
||||||
|
"200 activities" => Enum.take_random(activities, 200),
|
||||||
|
"500 activities" => Enum.take_random(activities, 500),
|
||||||
|
"2000 activities" => Enum.take_random(activities, 2000),
|
||||||
|
"4096 activities" => Enum.take_random(activities, 4096)
|
||||||
|
})
|
||||||
|
else
|
||||||
|
inputs
|
||||||
|
end
|
||||||
|
|
||||||
Benchee.run(
|
Benchee.run(
|
||||||
%{
|
%{
|
||||||
"Parallel rendering" => fn activities ->
|
|
||||||
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
|
|
||||||
activities: activities,
|
|
||||||
for: user,
|
|
||||||
as: :activity
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
"Standart rendering" => fn activities ->
|
"Standart rendering" => fn activities ->
|
||||||
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
|
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
|
||||||
activities: activities,
|
activities: activities,
|
||||||
for: user,
|
for: user,
|
||||||
as: :activity,
|
as: :activity
|
||||||
parallel: false
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
|
@ -73,14 +73,12 @@ defp reblogged?(activity, user) do
|
||||||
|
|
||||||
def render("index.json", opts) do
|
def render("index.json", opts) do
|
||||||
replied_to_activities = get_replied_to_activities(opts.activities)
|
replied_to_activities = get_replied_to_activities(opts.activities)
|
||||||
parallel = unless is_nil(opts[:parallel]), do: opts[:parallel], else: true
|
|
||||||
|
|
||||||
opts.activities
|
opts.activities
|
||||||
|> safe_render_many(
|
|> safe_render_many(
|
||||||
StatusView,
|
StatusView,
|
||||||
"status.json",
|
"status.json",
|
||||||
Map.put(opts, :replied_to_activities, replied_to_activities),
|
Map.put(opts, :replied_to_activities, replied_to_activities)
|
||||||
parallel
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -66,23 +66,9 @@ def safe_render(view, template, assigns \\ %{}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Same as `render_many/4` but wrapped in rescue block and parallelized (unless disabled by passing false as a fifth argument).
|
Same as `render_many/4` but wrapped in rescue block.
|
||||||
"""
|
"""
|
||||||
def safe_render_many(collection, view, template, assigns \\ %{}, parallel \\ true)
|
def safe_render_many(collection, view, template, assigns \\ %{}) do
|
||||||
|
|
||||||
def safe_render_many(collection, view, template, assigns, true) do
|
|
||||||
Enum.map(collection, fn resource ->
|
|
||||||
Task.async(fn ->
|
|
||||||
as = Map.get(assigns, :as) || view.__resource__
|
|
||||||
assigns = Map.put(assigns, as, resource)
|
|
||||||
safe_render(view, template, assigns)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|> Enum.map(&Task.await(&1, :infinity))
|
|
||||||
|> Enum.filter(& &1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def safe_render_many(collection, view, template, assigns, false) do
|
|
||||||
Enum.map(collection, fn resource ->
|
Enum.map(collection, fn resource ->
|
||||||
as = Map.get(assigns, :as) || view.__resource__
|
as = Map.get(assigns, :as) || view.__resource__
|
||||||
assigns = Map.put(assigns, as, resource)
|
assigns = Map.put(assigns, as, resource)
|
||||||
|
|
Loading…
Reference in a new issue