dbprune: add more logs

Pruning can go on for a long time; give admins some insight into that
something is happening to make it less frustrating and to make it easier
which part of the process is stalled should this happen.

Again most of the changes are merely reindents;
review with whitespace changes hidden recommended.
This commit is contained in:
Oneric 2024-05-15 01:33:41 +02:00
parent 1d4c212441
commit 24bab63cd8
1 changed files with 94 additions and 77 deletions

View File

@ -68,6 +68,8 @@ defmodule Mix.Tasks.Pleroma.Database do
""" """
|> Repo.query([], timeout: :infinity) |> Repo.query([], timeout: :infinity)
Logger.info("Prune activity singles: deleted #{del_single} rows...")
# Prune activities who link to an array of objects # Prune activities who link to an array of objects
{:ok, %{:num_rows => del_array}} = {:ok, %{:num_rows => del_array}} =
""" """
@ -88,6 +90,8 @@ defmodule Mix.Tasks.Pleroma.Database do
""" """
|> Repo.query([], timeout: :infinity) |> Repo.query([], timeout: :infinity)
Logger.info("Prune activity arrays: deleted #{del_array} rows...")
del_single + del_array del_single + del_array
end end
@ -222,6 +226,7 @@ defmodule Mix.Tasks.Pleroma.Database do
Logger.info(log_message) Logger.info(log_message)
{del_obj, _} =
if Keyword.get(options, :keep_threads) do if Keyword.get(options, :keep_threads) do
# We want to delete objects from threads where # We want to delete objects from threads where
# 1. the newest post is still old # 1. the newest post is still old
@ -288,9 +293,12 @@ defmodule Mix.Tasks.Pleroma.Database do
end end
|> Repo.delete_all(timeout: :infinity) |> Repo.delete_all(timeout: :infinity)
Logger.info("Deleted #{del_obj} objects...")
if !Keyword.get(options, :keep_threads) do if !Keyword.get(options, :keep_threads) do
# Without the --keep-threads option, it's possible that bookmarked # Without the --keep-threads option, it's possible that bookmarked
# objects have been deleted. We remove the corresponding bookmarks. # objects have been deleted. We remove the corresponding bookmarks.
{:ok, %{:num_rows => del_bookmarks}} =
""" """
delete from public.bookmarks delete from public.bookmarks
where id in ( where id in (
@ -301,12 +309,16 @@ defmodule Mix.Tasks.Pleroma.Database do
) )
""" """
|> Repo.query([], timeout: :infinity) |> Repo.query([], timeout: :infinity)
Logger.info("Deleted #{del_bookmarks} orphaned bookmarks...")
end end
if Keyword.get(options, :prune_orphaned_activities) do if Keyword.get(options, :prune_orphaned_activities) do
prune_orphaned_activities() del_activities = prune_orphaned_activities()
Logger.info("Deleted #{del_activities} orphaned activities...")
end end
{:ok, %{:num_rows => del_hashtags}} =
""" """
DELETE FROM hashtags AS ht DELETE FROM hashtags AS ht
WHERE NOT EXISTS ( WHERE NOT EXISTS (
@ -315,9 +327,14 @@ defmodule Mix.Tasks.Pleroma.Database do
""" """
|> Repo.query() |> Repo.query()
Logger.info("Deleted #{del_hashtags} no longer used hashtags...")
if Keyword.get(options, :vacuum) do if Keyword.get(options, :vacuum) do
Logger.info("Starting vacuum...")
Maintenance.vacuum("full") Maintenance.vacuum("full")
end end
Logger.info("All done!")
end end
def run(["prune_task"]) do def run(["prune_task"]) do