mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
avoid race condition
This commit is contained in:
parent
71289b9435
commit
f6d3468c98
2 changed files with 8 additions and 2 deletions
|
@ -207,7 +207,13 @@ def find_actor_or_create(actor: str) -> Union[User, Community, None]:
|
|||
|
||||
if user is not None:
|
||||
if not user.is_local() and user.ap_fetched_at < utcnow() - timedelta(days=7):
|
||||
refresh_user_profile(user.id)
|
||||
# To reduce load on remote servers, refreshing the user profile happens after a delay of 1 to 10 seconds. Meanwhile, subsequent calls to
|
||||
# find_actor_or_create() which happen to be for the same actor might queue up refreshes of the same user. To avoid this, set a flag to
|
||||
# indicate that user is currently being refreshed.
|
||||
refresh_in_progress = cache.get(f'refreshing_{user.id}')
|
||||
if not refresh_in_progress:
|
||||
cache.set(f'refreshing_{user.id}', True, timeout=30)
|
||||
refresh_user_profile(user.id)
|
||||
return user
|
||||
else: # User does not exist in the DB, it's going to need to be created from it's remote home instance
|
||||
if actor.startswith('https://'):
|
||||
|
|
|
@ -586,7 +586,7 @@ class PostReply(db.Model):
|
|||
|
||||
search_vector = db.Column(TSVectorType('body'))
|
||||
|
||||
author = db.relationship('User', lazy='joined', foreign_keys=[user_id], single_parent=True)
|
||||
author = db.relationship('User', lazy='joined', foreign_keys=[user_id], single_parent=True, overlaps="post_replies")
|
||||
|
||||
def is_local(self):
|
||||
return self.ap_id is None or self.ap_id.startswith('https://' + current_app.config['SERVER_NAME'])
|
||||
|
|
Loading…
Add table
Reference in a new issue