Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
disable autoflush in refresh_posts, fixing deadlocks. closes GH-19
Browse files Browse the repository at this point in the history
  • Loading branch information
codl committed Mar 11, 2019
1 parent 78c84ed commit 6d6184f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions libforget/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6d6184f

Please sign in to comment.