don't load pinned activities in due_expirations
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Wed, 12 Aug 2020 16:46:47 +0000 (19:46 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Wed, 12 Aug 2020 16:46:47 +0000 (19:46 +0300)
lib/mix/tasks/pleroma/database.ex
lib/pleroma/activity.ex
lib/pleroma/activity_expiration.ex
test/activity_expiration_test.exs

index 0142071a86c74e265b575a9a3cdc9bf07939c4b5..22a325b477b7574c7c9c8493f174218039925c7f 100644 (file)
@@ -150,9 +150,7 @@ defmodule Mix.Tasks.Pleroma.Database do
     |> Pleroma.RepoStreamer.chunk_stream(100)
     |> Stream.each(fn activities ->
       Enum.each(activities, fn activity ->
-        user = User.get_cached_by_ap_id(activity.actor)
-
-        if activity.id not in user.pinned_activities do
+        if not Pleroma.Activity.pinned_by_actor?(activity) do
           expires_at = Timex.shift(activity.inserted_at, days: days)
           Pleroma.ActivityExpiration.create(activity, expires_at, false)
         end
index c3cea8d2a2a24284a03e9d8dd15aaec7a245e11a..97feebeaa641b1e17f8ce71e6fd4bdd3a201dfee 100644 (file)
@@ -340,4 +340,10 @@ defmodule Pleroma.Activity do
       _ -> nil
     end
   end
+
+  @spec pinned_by_actor?(Activity.t()) :: boolean()
+  def pinned_by_actor?(%Activity{} = activity) do
+    actor = user_actor(activity)
+    activity.id in actor.pinned_activities
+  end
 end
index 84edf68ef3e3f20a20bc3169ac9a3b4639d253cd..955f0578ee65ed896907dfb1df35fd58c99437f3 100644 (file)
@@ -47,7 +47,11 @@ defmodule Pleroma.ActivityExpiration do
     ActivityExpiration
     |> where([exp], exp.scheduled_at < ^naive_datetime)
     |> limit(50)
+    |> preload(:activity)
     |> Repo.all()
+    |> Enum.reject(fn %{activity: activity} ->
+      Activity.pinned_by_actor?(activity)
+    end)
   end
 
   def validate_scheduled_at(changeset, false), do: changeset
index d75c06cc7e61aaad1a2dc22f32ec24334c67c691..f86d7982623dfe5b5c1ea87ecf919ba460b5869a 100644 (file)
@@ -11,7 +11,10 @@ defmodule Pleroma.ActivityExpirationTest do
 
   test "finds activities due to be deleted only" do
     activity = insert(:note_activity)
-    expiration_due = insert(:expiration_in_the_past, %{activity_id: activity.id})
+
+    expiration_due =
+      insert(:expiration_in_the_past, %{activity_id: activity.id}) |> Repo.preload(:activity)
+
     activity2 = insert(:note_activity)
     insert(:expiration_in_the_future, %{activity_id: activity2.id})