|> 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
_ -> 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
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
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})