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)
|
api = get_api_for_acc(acc)
|
||||||
|
|
||||||
new_posts = list()
|
new_posts = list()
|
||||||
for post in posts:
|
with db.session.no_autoflush:
|
||||||
try:
|
for post in posts:
|
||||||
status = api.status(post.mastodon_id)
|
print('Refreshing {}'.format(post))
|
||||||
new_post = db.session.merge(
|
try:
|
||||||
post_from_api_object(status, post.mastodon_instance))
|
status = api.status(post.mastodon_id)
|
||||||
new_post.touch()
|
new_post = db.session.merge(
|
||||||
new_posts.append(new_post)
|
post_from_api_object(status, post.mastodon_instance))
|
||||||
except MastodonNotFoundError:
|
new_post.touch()
|
||||||
db.session.delete(post)
|
new_posts.append(new_post)
|
||||||
except (MastodonAPIError,
|
except MastodonNotFoundError:
|
||||||
MastodonNetworkError,
|
db.session.delete(post)
|
||||||
MastodonRatelimitError) as e:
|
except (MastodonAPIError,
|
||||||
raise TemporaryError(e)
|
MastodonNetworkError,
|
||||||
|
MastodonRatelimitError) as e:
|
||||||
|
raise TemporaryError(e)
|
||||||
|
|
||||||
return new_posts
|
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')
|
Post.query.with_parent(account, 'posts')
|
||||||
.filter(Post.created_at + account.policy_keep_younger <= db.func.now())
|
.filter(Post.created_at + account.policy_keep_younger <= db.func.now())
|
||||||
.filter(~Post.id.in_(db.select((latest_n_posts.c.id, )))).order_by(
|
.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
|
to_delete = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue