Show progress in refresh_counter_cache task
authorRoman Chvanikov <chvanikoff@pm.me>
Sat, 9 May 2020 08:43:31 +0000 (11:43 +0300)
committerRoman Chvanikov <chvanikoff@pm.me>
Sat, 9 May 2020 08:43:31 +0000 (11:43 +0300)
lib/mix/tasks/pleroma/refresh_counter_cache.ex

index 280201befcfd0ad0fbeabe6bac4aa51afaeeb8ba..b44e2545d08b6fc4f7b799eed585e0e31ac2dd4f 100644 (file)
@@ -17,14 +17,21 @@ defmodule Mix.Tasks.Pleroma.RefreshCounterCache do
   def run([]) do
     Mix.Pleroma.start_pleroma()
 
-    Activity
-    |> distinct([a], true)
-    |> select([a], fragment("split_part(?, '/', 3)", a.actor))
-    |> Repo.all()
-    |> Enum.each(fn instance ->
+    instances =
+      Activity
+      |> distinct([a], true)
+      |> select([a], fragment("split_part(?, '/', 3)", a.actor))
+      |> Repo.all()
+
+    instances
+    |> Enum.with_index(1)
+    |> Enum.each(fn {instance, i} ->
       counters = instance_counters(instance)
       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)
 
     Mix.Pleroma.shell_info("Done")