From: Alexander Strizhakov Date: Wed, 12 Aug 2020 16:46:47 +0000 (+0300) Subject: don't load pinned activities in due_expirations X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=3ab83f837eb9c454b91374c6aeb14b37e8fdd3b1;p=akkoma don't load pinned activities in due_expirations --- diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index 0142071a8..22a325b47 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -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 diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index c3cea8d2a..97feebeaa 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -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 diff --git a/lib/pleroma/activity_expiration.ex b/lib/pleroma/activity_expiration.ex index 84edf68ef..955f0578e 100644 --- a/lib/pleroma/activity_expiration.ex +++ b/lib/pleroma/activity_expiration.ex @@ -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 diff --git a/test/activity_expiration_test.exs b/test/activity_expiration_test.exs index d75c06cc7..f86d79826 100644 --- a/test/activity_expiration_test.exs +++ b/test/activity_expiration_test.exs @@ -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})