Show progress in refresh_counter_cache task

This commit is contained in:
Roman Chvanikov 2020-05-09 11:43:31 +03:00
parent 942093683a
commit 01b06d6dbf
1 changed files with 13 additions and 6 deletions

View File

@ -17,14 +17,21 @@ defmodule Mix.Tasks.Pleroma.RefreshCounterCache do
def run([]) do def run([]) do
Mix.Pleroma.start_pleroma() Mix.Pleroma.start_pleroma()
Activity instances =
|> distinct([a], true) Activity
|> select([a], fragment("split_part(?, '/', 3)", a.actor)) |> distinct([a], true)
|> Repo.all() |> select([a], fragment("split_part(?, '/', 3)", a.actor))
|> Enum.each(fn instance -> |> Repo.all()
instances
|> Enum.with_index(1)
|> Enum.each(fn {instance, i} ->
counters = instance_counters(instance) counters = instance_counters(instance)
CounterCache.set(instance, counters) CounterCache.set(instance, counters)
Mix.Pleroma.shell_info("Setting #{instance} counters: #{inspect(counters)}")
Mix.Pleroma.shell_info(
"[#{i}/#{length(instances)}] Setting #{instance} counters: #{inspect(counters)}"
)
end) end)
Mix.Pleroma.shell_info("Done") Mix.Pleroma.shell_info("Done")