Ensure post pruning has a random selection element

This commit is contained in:
Andrew Godwin 2023-11-14 00:04:18 -07:00
parent dc397903b2
commit cc9e397f60

View file

@ -27,16 +27,18 @@ class Command(BaseCommand):
sys.exit(2)
# Find a set of posts that match the initial criteria
print(f"Running query to find up to {number} old posts...")
posts = Post.objects.filter(
posts = (
Post.objects.filter(
local=False,
created__lt=timezone.now()
- datetime.timedelta(days=settings.SETUP.REMOTE_PRUNE_HORIZON),
).exclude(
)
.exclude(
Q(interactions__identity__local=True)
| Q(visibility=Post.Visibilities.mentioned)
)[
:number
]
)
.order_by("?")[:number]
)
post_ids_and_uris = dict(posts.values_list("object_uri", "id"))
print(f" found {len(post_ids_and_uris)}")