fix: posts not getting refreshed
turns out i was not touching updated_at, so i'd always be refreshing the same posts unless one of them actually changed this is embarassing, there are posts in the DB that haven't been refreshed since 2017
This commit is contained in:
parent
68ac747f7e
commit
d5e0b43c9e
|
@ -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
|
||||||
|
@ -185,16 +186,14 @@ 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([
|
raise TemporaryError(e)
|
||||||
err in str(e)
|
|
||||||
for err in ('Endpoint not found', 'Record not found')]):
|
|
||||||
db.session.delete(post)
|
|
||||||
else:
|
|
||||||
raise TemporaryError(e)
|
|
||||||
|
|
||||||
return new_posts
|
return new_posts
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,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
|
||||||
|
|
2
tasks.py
2
tasks.py
|
@ -231,6 +231,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':
|
||||||
|
|
Loading…
Reference in New Issue