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