Purge Rejected Follow requests in daily task #334
3 changed files with 48 additions and 0 deletions
|
@ -35,6 +35,17 @@ def prune_removes do
|
||||||
|> Repo.delete_all(timeout: :infinity)
|
|> Repo.delete_all(timeout: :infinity)
|
||||||
end
|
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
|
defp cutoff do
|
||||||
DateTime.utc_now() |> Timex.shift(days: -@cutoff)
|
DateTime.utc_now() |> Timex.shift(days: -@cutoff)
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,4 +24,40 @@ test "it prunes old delete objects" do
|
||||||
refute Activity.get_by_id(old_delete.id)
|
refute Activity.get_by_id(old_delete.id)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -469,6 +469,7 @@ def follow_activity_factory(attrs \\ %{}) do
|
||||||
data: data,
|
data: data,
|
||||||
actor: follower.ap_id
|
actor: follower.ap_id
|
||||||
}
|
}
|
||||||
|
|> Map.merge(attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_activity_factory(attrs \\ %{}) do
|
def report_activity_factory(attrs \\ %{}) do
|
||||||
|
|
Loading…
Reference in a new issue