Merge branch 'fix-refresh'

This commit is contained in:
codl 2019-02-24 16:36:23 +01:00
commit 61131f4298
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
4 changed files with 9 additions and 6 deletions

View File

@ -3,6 +3,7 @@
* implemented a more robust fetching algorithm, which should prevent accounts getting stuck with only a fraction of their posts fetched ([GH-13](https://github.com/codl/forget/issues/13)) * implemented a more robust fetching algorithm, which should prevent accounts getting stuck with only a fraction of their posts fetched ([GH-13](https://github.com/codl/forget/issues/13))
* fix: picture tags having an extra comma * fix: picture tags having an extra comma
* fix: outdated joke in about page * fix: outdated joke in about page
* fix: posts' status not getting refreshed (ie whether or not they were faved, or deleted externally)
* internals: removed `x-` prefix from custom headers, as per [section 8.3.1 of RFC7231](https://httpwg.org/specs/rfc7231.html#considerations.for.new.header.fields) * internals: removed `x-` prefix from custom headers, as per [section 8.3.1 of RFC7231](https://httpwg.org/specs/rfc7231.html#considerations.for.new.header.fields)
## v1.4.1 (security update) ## v1.4.1 (security update)

View File

@ -1,6 +1,7 @@
from mastodon import Mastodon from mastodon import Mastodon
from mastodon.Mastodon import MastodonAPIError,\ from mastodon.Mastodon import MastodonAPIError,\
MastodonNetworkError,\ MastodonNetworkError,\
MastodonNotFoundError,\
MastodonRatelimitError,\ MastodonRatelimitError,\
MastodonUnauthorizedError MastodonUnauthorizedError
from model import MastodonApp, Account, OAuthToken, Post, MastodonInstance from model import MastodonApp, Account, OAuthToken, Post, MastodonInstance
@ -164,15 +165,13 @@ def refresh_posts(posts):
status = api.status(post.mastodon_id) status = api.status(post.mastodon_id)
new_post = db.session.merge( new_post = db.session.merge(
post_from_api_object(status, post.mastodon_instance)) post_from_api_object(status, post.mastodon_instance))
new_post.touch()
new_posts.append(new_post) new_posts.append(new_post)
except MastodonNotFoundError:
db.session.delete(post)
except (MastodonAPIError, except (MastodonAPIError,
MastodonNetworkError, MastodonNetworkError,
MastodonRatelimitError) as e: MastodonRatelimitError) as e:
if any([
err in str(e)
for err in ('Endpoint not found', 'Record not found')]):
db.session.delete(post)
else:
raise TemporaryError(e) raise TemporaryError(e)
return new_posts return new_posts

View File

@ -167,6 +167,7 @@ def refresh_posts(posts):
db.session.delete(post) db.session.delete(post)
else: else:
post = db.session.merge(post_from_api_tweet_object(tweet)) post = db.session.merge(post_from_api_tweet_object(tweet))
post.touch()
refreshed_posts.append(post) refreshed_posts.append(post)
return refreshed_posts return refreshed_posts

View File

@ -296,6 +296,8 @@ def refresh_posts(posts):
def refresh_account(account_id): def refresh_account(account_id):
account = Account.query.get(account_id) account = Account.query.get(account_id)
print("Refreshing account {}".format(account))
try: try:
limit = 100 limit = 100
if account.service == 'mastodon': if account.service == 'mastodon':