fix(retention): keep threads whose post a local user quoted

A quote has a context of its own, so the quoted remote thread counted as
untouched and was evicted, breaking the local quote. On lain.com 45 of
134 quoted posts went this way. The objects_quote_url index keeps the
lookup at one probe per post.
This commit is contained in:
Lain Soykaf 2026-09-25 08:50:41 +04:00
commit e93f05a79f
No known key found for this signature in database
5 changed files with 53 additions and 5 deletions

View file

@ -18,6 +18,7 @@ defmodule Pleroma.Retention do
users all carry the thread's context),
* is bookmarked by a local user,
* is addressed to a local user (direct messages and mentions),
* is a post quoted by a local post,
* still has a notification for a local user,
* is a report (Flag),
@ -245,6 +246,18 @@ defmodule Pleroma.Retention do
^local_prefix()
)
)
# A local quote has a context of its own, so look up quotes of the posts
# here; the objects_quote_url index is on the jsonb value.
|> having(
[a],
not fragment(
"bool_or(? ->> 'type' = 'Create' AND EXISTS (SELECT 1 FROM objects q WHERE q.data -> 'quoteUrl' = to_jsonb(associated_object_id(?)) AND left(q.data ->> 'actor', ?) = ?))",
a.data,
a.data,
^local_prefix_length(),
^local_prefix()
)
)
|> maybe_keep_non_public(Keyword.get(opts, :keep_non_public, false) == true)
end