Merge pull request #169 from codl/fix-deadlock
disable autoflush in refresh_posts, fixing deadlocks. closes GH-19
This commit is contained in:
commit
1430361763
|
@ -160,19 +160,21 @@ def refresh_posts(posts):
|
|||
api = get_api_for_acc(acc)
|
||||
|
||||
new_posts = list()
|
||||
for post in posts:
|
||||
try:
|
||||
status = api.status(post.mastodon_id)
|
||||
new_post = db.session.merge(
|
||||
post_from_api_object(status, post.mastodon_instance))
|
||||
new_post.touch()
|
||||
new_posts.append(new_post)
|
||||
except MastodonNotFoundError:
|
||||
db.session.delete(post)
|
||||
except (MastodonAPIError,
|
||||
MastodonNetworkError,
|
||||
MastodonRatelimitError) as e:
|
||||
raise TemporaryError(e)
|
||||
with db.session.no_autoflush:
|
||||
for post in posts:
|
||||
print('Refreshing {}'.format(post))
|
||||
try:
|
||||
status = api.status(post.mastodon_id)
|
||||
new_post = db.session.merge(
|
||||
post_from_api_object(status, post.mastodon_instance))
|
||||
new_post.touch()
|
||||
new_posts.append(new_post)
|
||||
except MastodonNotFoundError:
|
||||
db.session.delete(post)
|
||||
except (MastodonAPIError,
|
||||
MastodonNetworkError,
|
||||
MastodonRatelimitError) as e:
|
||||
raise TemporaryError(e)
|
||||
|
||||
return new_posts
|
||||
|
||||
|
|
2
tasks.py
2
tasks.py
|
@ -234,7 +234,7 @@ def delete_from_account(account_id):
|
|||
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).with_for_update().all())
|
||||
db.func.random()).limit(100).all())
|
||||
|
||||
to_delete = None
|
||||
|
||||
|
|
Loading…
Reference in New Issue