Ensure only Note objects are set to expire
authorMark Felder <feld@FreeBSD.org>
Tue, 11 Aug 2020 16:28:22 +0000 (11:28 -0500)
committerMark Felder <feld@FreeBSD.org>
Tue, 11 Aug 2020 16:28:22 +0000 (11:28 -0500)
lib/mix/tasks/pleroma/database.ex

index b2dc3d0f3b81075bbe12ac083e0d0f65331d9a9d..7d8f00b089b50f6d2dc686a6865a8eec72a38ff1 100644 (file)
@@ -134,14 +134,23 @@ defmodule Mix.Tasks.Pleroma.Database do
 
     Pleroma.Activity
     |> join(:left, [a], u in assoc(a, :expiration))
+    |> join(:inner, [a, _u], o in Object,
+      on:
+        fragment(
+          "(?->>'id') = COALESCE((?)->'object'->> 'id', (?)->>'object')",
+          o.data,
+          a.data,
+          a.data
+        )
+    )
     |> where(local: true)
     |> where([a, u], is_nil(u))
     |> where([a], fragment("(? ->> 'type'::text) = 'Create'", a.data))
+    |> where([_a, _u, o], fragment("?->>'type' = 'Note'", o.data))
     |> Pleroma.RepoStreamer.chunk_stream(100)
     |> Stream.each(fn activities ->
       Enum.each(activities, fn activity ->
         expires_at = Timex.shift(activity.inserted_at, days: days)
-
         Pleroma.ActivityExpiration.create(activity, expires_at, false)
       end)
     end)