don't load pinned activities in due_expirations

This commit is contained in:
Alexander Strizhakov 2020-08-12 19:46:47 +03:00
parent 091da10832
commit 3ab83f837e
No known key found for this signature in database
GPG key ID: 022896A53AEF1381
4 changed files with 15 additions and 4 deletions

View 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

View 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

View 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

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