massive optimisation on getting eligible posts
uhh the subquery is run for every single row so, with a long enough time limit and enough posts thats. a several minute long SELECT
This commit is contained in:
parent
b428788fc0
commit
5bce4c9b17
4
model.py
4
model.py
|
@ -90,10 +90,10 @@ class Account(TimestampMixin, RemoteIDMixin):
|
|||
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 = db.session.query(Post.id).with_parent(self).order_by(db.desc(Post.created_at)).limit(self.policy_keep_latest)
|
||||
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 + self.policy_keep_younger <= db.func.now()).\
|
||||
filter(~Post.id.in_(latest_n_posts))
|
||||
except_(latest_n_posts)
|
||||
if(self.policy_keep_favourites):
|
||||
query = query.filter_by(favourite = False)
|
||||
if(self.policy_keep_media):
|
||||
|
|
4
tasks.py
4
tasks.py
|
@ -132,10 +132,10 @@ def queue_deletes():
|
|||
@app.task(autoretry_for=(TwitterError, URLError))
|
||||
def delete_from_account(account_id):
|
||||
account = Account.query.get(account_id)
|
||||
latest_n_posts = db.session.query(Post.id).with_parent(account).order_by(db.desc(Post.created_at)).limit(account.policy_keep_latest)
|
||||
latest_n_posts = Post.query.with_parent(account).order_by(db.desc(Post.created_at)).limit(account.policy_keep_latest)
|
||||
posts = Post.query.with_parent(account).\
|
||||
filter(Post.created_at + account.policy_keep_younger <= db.func.now()).\
|
||||
filter(~Post.id.in_(latest_n_posts)).\
|
||||
except_(latest_n_posts).\
|
||||
order_by(db.func.random()).limit(100).all()
|
||||
|
||||
posts = refresh_posts(posts)
|
||||
|
|
Loading…
Reference in New Issue