update and sync defederation subscriptions each day

This commit is contained in:
rimu 2024-12-27 20:24:17 +13:00
parent de11aa6c50
commit 4d18627f0e

View file

@ -7,7 +7,6 @@ from random import randint
from time import sleep from time import sleep
import flask import flask
import httpx
from flask import json, current_app from flask import json, current_app
from flask_babel import _ from flask_babel import _
from sqlalchemy import or_, desc, text from sqlalchemy import or_, desc, text
@ -20,14 +19,14 @@ from app.activitypub.signature import RsaKeys
from app.activitypub.util import find_actor_or_create from app.activitypub.util import find_actor_or_create
from app.auth.util import random_token from app.auth.util import random_token
from app.constants import NOTIF_COMMUNITY, NOTIF_POST, NOTIF_REPLY from app.constants import NOTIF_COMMUNITY, NOTIF_POST, NOTIF_REPLY
from app.email import send_verification_email, send_email from app.email import send_email
from app.models import Settings, BannedInstances, Interest, Role, User, RolePermission, Domain, ActivityPubLog, \ from app.models import Settings, BannedInstances, Role, User, RolePermission, Domain, ActivityPubLog, \
utcnow, Site, Instance, File, Notification, Post, CommunityMember, NotificationSubscription, PostReply, Language, \ utcnow, Site, Instance, File, Notification, Post, CommunityMember, NotificationSubscription, PostReply, Language, \
Tag, InstanceRole, Community Tag, InstanceRole, Community, DefederationSubscription
from app.post.routes import post_delete_post from app.post.routes import post_delete_post
from app.utils import file_get_contents, retrieve_block_list, blocked_domains, retrieve_peertube_block_list, \ from app.utils import retrieve_block_list, blocked_domains, retrieve_peertube_block_list, \
shorten_string, get_request, html_to_text, blocked_communities, ap_datetime, gibberish, get_request_instance, \ shorten_string, get_request, blocked_communities, gibberish, get_request_instance, \
instance_banned, recently_upvoted_post_replies, recently_upvoted_posts, jaccard_similarity instance_banned, recently_upvoted_post_replies, recently_upvoted_posts, jaccard_similarity, download_defeds
def register(app): def register(app):
@ -221,6 +220,10 @@ def register(app):
{'cutoff': utcnow()}) {'cutoff': utcnow()})
db.session.commit() db.session.commit()
# update and sync defederation subscriptions
for defederation_sub in DefederationSubscription.query.all():
download_defeds(defederation_sub.id, defederation_sub.domain)
# Check for dormant or dead instances # Check for dormant or dead instances
try: try:
# Check for dormant or dead instances # Check for dormant or dead instances