From 41cadc1f72f498d51a9eb0cf1878b823084b0cb9 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 17 Aug 2024 10:31:22 +1200 Subject: [PATCH] only refresh community and user profiles of online instances --- app/activitypub/util.py | 4 ++-- app/models.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index fed9d691..bbda307a 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -478,7 +478,7 @@ def refresh_user_profile(user_id): @celery.task def refresh_user_profile_task(user_id): user = User.query.get(user_id) - if user: + if user and user.instance.online(): try: actor_data = get_request(user.ap_public_url, headers={'Accept': 'application/activity+json'}) except requests.exceptions.ReadTimeout: @@ -557,7 +557,7 @@ def refresh_community_profile(community_id): @celery.task def refresh_community_profile_task(community_id): community = Community.query.get(community_id) - if community and not community.is_local(): + if community and community.instance.online() and not community.is_local(): try: actor_data = get_request(community.ap_public_url, headers={'Accept': 'application/activity+json'}) except requests.exceptions.ReadTimeout: diff --git a/app/models.py b/app/models.py index 26d630c2..b406fc64 100644 --- a/app/models.py +++ b/app/models.py @@ -408,6 +408,7 @@ class Community(db.Model): icon = db.relationship('File', foreign_keys=[icon_id], single_parent=True, backref='community', cascade="all, delete-orphan") image = db.relationship('File', foreign_keys=[image_id], single_parent=True, cascade="all, delete-orphan") languages = db.relationship('Language', lazy='dynamic', secondary=community_language, backref=db.backref('communities', lazy='dynamic')) + instance = db.relationship('Instance', lazy='dynamic', foreign_keys=[instance_id]) def language_ids(self): return [language.id for language in self.languages.all()]