From 36860b6bf7f07f449fd44093c145c6619661ed99 Mon Sep 17 00:00:00 2001 From: codl Date: Sat, 11 May 2019 20:21:43 +0200 Subject: [PATCH] ignore posts that are not known to match policy until now, delete_from_account would only ignore posts that were too young, but would fetch and refresh posts that didn't match fave/media/DM policies. this was fine most of the time but would result in a lot of refreshes if those policies were very restrictive. now these policies are respected when selecting candidate posts for deletion closes #174 --- tasks.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index bcbbc50..233bd4c 100644 --- a/tasks.py +++ b/tasks.py @@ -234,8 +234,24 @@ def delete_from_account(account_id): posts = ( Post.query.with_parent(account, 'posts') .filter(Post.created_at + account.policy_keep_younger <= db.func.now()) - .filter(~Post.id.in_(db.select((latest_n_posts.c.id, )))).order_by( - db.func.random()).limit(100).all()) + .filter(~Post.id.in_(db.select((latest_n_posts.c.id, ))))) + + if(account.policy_keep_favourites != 'none'): + posts = posts.filter(db.or_( + Post.favourite == (account.policy_keep_favourites == 'deleteonly'), + Post.is_reblog)) + if(account.policy_keep_media != 'none'): + posts = posts.filter(db.or_( + Post.has_media == (account.policy_keep_media == 'deleteonly'), + Post.is_reblog)) + if(account.policy_keep_direct): + posts = posts.filter(~Post.direct) + + limit = 100 + if account.service == 'mastodon': + limit = 10 + + posts = posts.order_by(db.func.random()).limit(limit).all() to_delete = None