def estimate_eligible_for_delete(self):
"""
this is an estimation because we do not know if favourite status has
changed since last time a post was refreshed and it is unfeasible to
refresh every single post every time we need to know how many posts are
eligible to delete
"""
latest_n_posts = (Post.query.with_parent(self)
.order_by(db.desc(Post.created_at))
.limit(self.policy_keep_latest))
query = (Post.query.with_parent(self)
.filter(Post.created_at <=
db.func.now() - self.policy_keep_younger)
.except_(latest_n_posts))
if(self.policy_keep_favourites):
query = query.filter(db.or_(Post.favourite == False, Post.is_reblog))
if(self.policy_keep_media):
query = query.filter(db.or_(Post.has_media == False, Post.is_reblog))
if(self.policy_keep_direct):
query = query.filter(~Post.direct)
return query.count()
评论列表
文章目录