Also prune rejected Follow activities

This commit is contained in:
FloatingGhost 2022-12-03 22:05:48 +00:00
parent 1409f91d50
commit 55436d5823
3 changed files with 48 additions and 0 deletions

View File

@ -35,6 +35,17 @@ defmodule Pleroma.Activity.Pruner do
|> Repo.delete_all(timeout: :infinity)
end
def prune_stale_follow_requests do
before_time = cutoff()
from(a in Activity,
where:
fragment("?->>'type' = ?", a.data, "Follow") and a.inserted_at < ^before_time and
fragment("?->>'state' = ?", a.data, "reject")
)
|> Repo.delete_all(timeout: :infinity)
end
defp cutoff do
DateTime.utc_now() |> Timex.shift(days: -@cutoff)
end

View File

@ -24,4 +24,40 @@ defmodule Pleroma.Activity.PrunerTest do
refute Activity.get_by_id(old_delete.id)
end
end
describe "prune_stale_follow_requests" do
test "it prunes old follow requests" do
follower = insert(:user)
followee = insert(:user)
new_follow_request =
insert(
:follow_activity,
follower: follower,
followd: followee,
state: "reject"
)
old_not_rejected_request =
insert(:follow_activity,
follower: follower,
followd: followee,
state: "pending",
inserted_at: DateTime.utc_now() |> DateTime.add(-31 * 24, :hour)
)
old_follow_request =
insert(:follow_activity,
follower: follower,
followd: followee,
inserted_at: DateTime.utc_now() |> DateTime.add(-31 * 24, :hour),
state: "reject"
)
Pruner.prune_stale_follow_requests()
assert Activity.get_by_id(new_follow_request.id)
assert Activity.get_by_id(old_not_rejected_request.id)
refute Activity.get_by_id(old_follow_request.id)
end
end
end

View File

@ -469,6 +469,7 @@ defmodule Pleroma.Factory do
data: data,
actor: follower.ap_id
}
|> Map.merge(attrs)
end
def report_activity_factory(attrs \\ %{}) do