mirror of
https://git.youjo.love/youjo/youjo-be.git
synced 2024-11-20 05:49:54 +01:00
don't load pinned activities in due_expirations
This commit is contained in:
parent
091da10832
commit
3ab83f837e
4 changed files with 15 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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})
|
||||
|
||||
|
|
Loading…
Reference in a new issue