From 06bf189a3318a97eccaec7269ecebfdc108bfeb7 Mon Sep 17 00:00:00 2001 From: codl Date: Tue, 29 Aug 2017 20:45:42 +0200 Subject: [PATCH] an attempt at fixing the weird deadlock issue ive been having --- tasks.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tasks.py b/tasks.py index abdaef3..a2f8abb 100644 --- a/tasks.py +++ b/tasks.py @@ -171,14 +171,15 @@ def delete_from_account(account_id): account = Account.query.get(account_id) latest_n_posts = (Post.query.with_parent(account) .order_by(db.desc(Post.created_at)) - .limit(account.policy_keep_latest)) + .limit(account.policy_keep_latest) + .cte(name='latest')) posts = ( Post.query.with_parent(account) .filter( 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()) - .limit(100).all()) + .limit(100).with_for_update().all()) eligible = None