fix(retention): keep threads younger than a day over the watermark
Over the watermark the walk went up to the present, so posts that had just arrived could be evicted while people were reading them.
This commit is contained in:
parent
1a0212bf9a
commit
3cbcae2de3
4 changed files with 45 additions and 36 deletions
|
|
@ -58,6 +58,12 @@ defmodule Pleroma.RetentionTest do
|
|||
# and backdate it so it looks like an old federated post.
|
||||
defp make_remote_and_old(activity, old_date), do: age(activity, old_date, %{local: false})
|
||||
|
||||
defp days_ago(days) do
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(-days * 86_400)
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
end
|
||||
|
||||
defp make_old(activity, old_date), do: age(activity, old_date, %{})
|
||||
|
||||
defp old_remote_post(user, old_date, params \\ %{}) do
|
||||
|
|
@ -232,26 +238,15 @@ defmodule Pleroma.RetentionTest do
|
|||
refute Object.get_by_ap_id(newer.data["object"])
|
||||
end
|
||||
|
||||
test "evicts recent unpinned threads when over the object watermark" do
|
||||
test "evicts threads younger than the retention period when over the object watermark" do
|
||||
clear_config([:retention, :max_objects], 1)
|
||||
clear_config([:retention, :batch_size], 1)
|
||||
|
||||
remote_user = insert(:user, local: false)
|
||||
local_user = insert(:user)
|
||||
|
||||
{:ok, older} = CommonAPI.post(remote_user, %{status: "older"})
|
||||
|
||||
older
|
||||
|> Ecto.Changeset.change(%{
|
||||
local: false,
|
||||
updated_at:
|
||||
NaiveDateTime.utc_now() |> NaiveDateTime.add(-60) |> NaiveDateTime.truncate(:second)
|
||||
})
|
||||
|> Repo.update!()
|
||||
|
||||
{:ok, newer} = CommonAPI.post(remote_user, %{status: "newer"})
|
||||
newer |> Ecto.Changeset.change(%{local: false}) |> Repo.update!()
|
||||
|
||||
older = old_remote_post(remote_user, days_ago(3))
|
||||
newer = old_remote_post(remote_user, days_ago(2))
|
||||
{:ok, mine} = CommonAPI.post(local_user, %{status: "mine"})
|
||||
|
||||
assert %{contexts: 1} = Retention.run()
|
||||
|
|
@ -260,6 +255,16 @@ defmodule Pleroma.RetentionTest do
|
|||
assert Object.get_by_ap_id(mine.data["object"])
|
||||
end
|
||||
|
||||
test "keeps threads quiet for less than a day, even over the watermark" do
|
||||
clear_config([:retention, :max_objects], 0)
|
||||
remote_user = insert(:user, local: false)
|
||||
|
||||
post = old_remote_post(remote_user, NaiveDateTime.add(days_ago(1), 3_600))
|
||||
|
||||
assert %{contexts: 0} = Retention.run()
|
||||
assert Object.get_by_ap_id(post.data["object"])
|
||||
end
|
||||
|
||||
test "does not evict anything below the watermark" do
|
||||
clear_config([:retention, :max_objects], 100)
|
||||
remote_user = insert(:user, local: false)
|
||||
|
|
@ -447,8 +452,7 @@ defmodule Pleroma.RetentionTest do
|
|||
remote_user = insert(:user, local: false)
|
||||
|
||||
clear_config([:retention, :max_objects], 0)
|
||||
{:ok, recent} = CommonAPI.post(remote_user, %{status: "recent"})
|
||||
recent |> Ecto.Changeset.change(%{local: false}) |> Repo.update!()
|
||||
recent = old_remote_post(remote_user, days_ago(2))
|
||||
assert %{contexts: 1} = Retention.run()
|
||||
refute Object.get_by_ap_id(recent.data["object"])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue