mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-17 18:49:15 +00:00
dbprune: use query!
This commit is contained in:
parent
24bab63cd8
commit
5751637926
|
@ -50,7 +50,7 @@ def prune_orphaned_activities(limit \\ 0) when is_number(limit) do
|
||||||
# deleting useful activities should more types be added, keep typeof for singles.
|
# deleting useful activities should more types be added, keep typeof for singles.
|
||||||
|
|
||||||
# Prune activities who link to a single object
|
# Prune activities who link to a single object
|
||||||
{:ok, %{:num_rows => del_single}} =
|
%{:num_rows => del_single} =
|
||||||
"""
|
"""
|
||||||
delete from public.activities
|
delete from public.activities
|
||||||
where id in (
|
where id in (
|
||||||
|
@ -66,12 +66,12 @@ def prune_orphaned_activities(limit \\ 0) when is_number(limit) do
|
||||||
#{limit_arg}
|
#{limit_arg}
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|> Repo.query([], timeout: :infinity)
|
|> Repo.query!([], timeout: :infinity)
|
||||||
|
|
||||||
Logger.info("Prune activity singles: deleted #{del_single} rows...")
|
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}} =
|
%{:num_rows => del_array} =
|
||||||
"""
|
"""
|
||||||
delete from public.activities
|
delete from public.activities
|
||||||
where id in (
|
where id in (
|
||||||
|
@ -88,7 +88,7 @@ def prune_orphaned_activities(limit \\ 0) when is_number(limit) do
|
||||||
#{limit_arg}
|
#{limit_arg}
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|> Repo.query([], timeout: :infinity)
|
|> Repo.query!([], timeout: :infinity)
|
||||||
|
|
||||||
Logger.info("Prune activity arrays: deleted #{del_array} rows...")
|
Logger.info("Prune activity arrays: deleted #{del_array} rows...")
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ def run(["prune_objects" | args]) do
|
||||||
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}} =
|
%{:num_rows => del_bookmarks} =
|
||||||
"""
|
"""
|
||||||
delete from public.bookmarks
|
delete from public.bookmarks
|
||||||
where id in (
|
where id in (
|
||||||
|
@ -308,7 +308,7 @@ def run(["prune_objects" | args]) do
|
||||||
where o.id is null
|
where o.id is null
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|> Repo.query([], timeout: :infinity)
|
|> Repo.query!([], timeout: :infinity)
|
||||||
|
|
||||||
Logger.info("Deleted #{del_bookmarks} orphaned bookmarks...")
|
Logger.info("Deleted #{del_bookmarks} orphaned bookmarks...")
|
||||||
end
|
end
|
||||||
|
@ -318,14 +318,14 @@ def run(["prune_objects" | args]) do
|
||||||
Logger.info("Deleted #{del_activities} orphaned activities...")
|
Logger.info("Deleted #{del_activities} orphaned activities...")
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, %{:num_rows => del_hashtags}} =
|
%{:num_rows => del_hashtags} =
|
||||||
"""
|
"""
|
||||||
DELETE FROM hashtags AS ht
|
DELETE FROM hashtags AS ht
|
||||||
WHERE NOT EXISTS (
|
WHERE NOT EXISTS (
|
||||||
SELECT 1 FROM hashtags_objects hto
|
SELECT 1 FROM hashtags_objects hto
|
||||||
WHERE ht.id = hto.hashtag_id)
|
WHERE ht.id = hto.hashtag_id)
|
||||||
"""
|
"""
|
||||||
|> Repo.query()
|
|> Repo.query!()
|
||||||
|
|
||||||
Logger.info("Deleted #{del_hashtags} no longer used hashtags...")
|
Logger.info("Deleted #{del_hashtags} no longer used hashtags...")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue