mix prune_objects: remove unused hashtags after pruning remote objects
authorfaried nawaz <faried@gmail.com>
Tue, 20 Apr 2021 21:38:59 +0000 (02:38 +0500)
committerfaried nawaz <faried@gmail.com>
Fri, 7 May 2021 21:00:42 +0000 (02:00 +0500)
lib/mix/tasks/pleroma/database.ex

index e7f4b67a463d5b8b1dd540901b0db47e853d0a3b..53ad58b6458c2d9721ca8a57c307281327a1b64b 100644 (file)
@@ -96,6 +96,17 @@ defmodule Mix.Tasks.Pleroma.Database do
     )
     |> Repo.delete_all(timeout: :infinity)
 
+    prune_hashtags_query = """
+    delete from hashtags
+    where id in (
+      select id from hashtags as ht
+      left join hashtags_objects as hto
+      on hto.hashtag_id = ht.id
+      where hto.hashtag_id is null)
+    """
+
+    Repo.query(prune_hashtags_query)
+
     if Keyword.get(options, :vacuum) do
       Maintenance.vacuum("full")
     end