From 20ed4175e4e7ee2da4204c5bb60f66b952037e6f Mon Sep 17 00:00:00 2001 From: codl Date: Tue, 29 Aug 2017 17:44:50 +0200 Subject: [PATCH] limit to one tweet per delete round deleting hundreds of tweets every 40 seconds is making us hit the rate limit, dont do that --- tasks.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/tasks.py b/tasks.py index 6e8f3d6..2e43595 100644 --- a/tasks.py +++ b/tasks.py @@ -186,11 +186,11 @@ def delete_from_account(account_id): if account.service == 'twitter': action = lib.twitter.delete posts = refresh_posts(posts) - eligible = list( + eligible = random.choice(list( # nosec (post for post in posts if (not account.policy_keep_favourites or not post.favourite) and (not account.policy_keep_media or not post.has_media) - )) + ))) elif account.service == 'mastodon': action = lib.mastodon.delete for post in posts: @@ -199,21 +199,14 @@ def delete_from_account(account_id): (not account.policy_keep_favourites or not post.favourite) \ and (not account.policy_keep_media or not post.has_media)\ and (not account.policy_keep_direct or not post.direct): - eligible = refreshed + eligible = refreshed[0] break if eligible: - if account.policy_delete_every == timedelta(0) and len(eligible) > 1: - print("deleting all {} eligible posts for {}" - .format(len(eligible), account)) - for post in eligible: - account.touch_delete() - action(post) - else: - post = random.choice(eligible) # nosec - print("deleting {}".format(post)) - account.touch_delete() - action(post) + post = eligible + print("deleting {}".format(post)) + account.touch_delete() + action(post) db.session.commit()