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
This commit is contained in:
codl 2019-05-11 20:21:43 +02:00
parent dea3ab760a
commit 36860b6bf7
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
1 changed files with 18 additions and 2 deletions

View File

@ -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