disable autoflush in refresh_posts, fixing deadlocks. closes GH-19

This commit is contained in:
codl 2019-03-11 02:00:06 +00:00
parent 78c84ed92c
commit 6d6184f3d8
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
2 changed files with 16 additions and 14 deletions

View File

@ -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

View File

@ -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