From cc9e397f60046d84c4c7a4d2e7330b888b3c78c0 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 14 Nov 2023 00:04:18 -0700 Subject: [PATCH] Ensure post pruning has a random selection element --- activities/management/commands/pruneposts.py | 22 +++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/activities/management/commands/pruneposts.py b/activities/management/commands/pruneposts.py index 353ce57..19b8ea3 100644 --- a/activities/management/commands/pruneposts.py +++ b/activities/management/commands/pruneposts.py @@ -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( - local=False, - created__lt=timezone.now() - - datetime.timedelta(days=settings.SETUP.REMOTE_PRUNE_HORIZON), - ).exclude( - Q(interactions__identity__local=True) - | Q(visibility=Post.Visibilities.mentioned) - )[ - :number - ] + posts = ( + Post.objects.filter( + local=False, + created__lt=timezone.now() + - datetime.timedelta(days=settings.SETUP.REMOTE_PRUNE_HORIZON), + ) + .exclude( + Q(interactions__identity__local=True) + | Q(visibility=Post.Visibilities.mentioned) + ) + .order_by("?")[:number] + ) post_ids_and_uris = dict(posts.values_list("object_uri", "id")) print(f" found {len(post_ids_and_uris)}")