an attempt at fixing the weird deadlock issue ive been having

This commit is contained in:
codl 2017-08-29 20:45:42 +02:00
parent 6495135124
commit 06bf189a33
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
1 changed files with 4 additions and 3 deletions

View File

@ -171,14 +171,15 @@ def delete_from_account(account_id):
account = Account.query.get(account_id) account = Account.query.get(account_id)
latest_n_posts = (Post.query.with_parent(account) latest_n_posts = (Post.query.with_parent(account)
.order_by(db.desc(Post.created_at)) .order_by(db.desc(Post.created_at))
.limit(account.policy_keep_latest)) .limit(account.policy_keep_latest)
.cte(name='latest'))
posts = ( posts = (
Post.query.with_parent(account) Post.query.with_parent(account)
.filter( .filter(
Post.created_at + account.policy_keep_younger <= db.func.now()) Post.created_at + account.policy_keep_younger <= db.func.now())
.except_(latest_n_posts) .filter(~Post.id.in_(db.select((latest_n_posts.c.id,))))
.order_by(db.func.random()) .order_by(db.func.random())
.limit(100).all()) .limit(100).with_for_update().all())
eligible = None eligible = None