From 8cf6ac6c4435fd2fad89a31093df3ef43849881d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 20 May 2023 13:12:05 +0200 Subject: [PATCH] Continued: - added last_blocked to reduce requering instances to often (be nice!) --- blocks_empty.db | Bin 28672 -> 28672 bytes config.defaults.json | 3 ++- fba.py | 13 +++++++++++++ fetch_blocks.py | 4 +++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/blocks_empty.db b/blocks_empty.db index af1c0a79e8d3719772c01d6a9f66b355ca7a0634..dc11b3532ecb5e55ac3b2fa97761b1c6d8cbd73e 100644 GIT binary patch delta 113 zcmZp8z}WDBae}nqGX@3*b|_{9(lQfuj3u8j=y^}%<=0_g str: # NOISY-DEBUG: print("DEBUG: Calculating hash for domain:", domain) return sha256(domain.encode("utf-8")).hexdigest() +def update_last_blocked(domain: str): + # NOISY-DEBUG: print("DEBUG: Updating last_blocked for domain", domain) + + try: + c.execute("UPDATE instances SET last_blocked = ? WHERE domain = ?", [ + time.time(), + domain + ]) + + except: + print("ERROR: failed SQL query:", domain) + sys.exit(255) + def update_last_error(domain: str, res: any): # NOISY-DEBUG: print("DEBUG: domain,res.status_code", domain, res.status_code) diff --git a/fetch_blocks.py b/fetch_blocks.py index 6984348..93b6134 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -6,7 +6,7 @@ import re import fba fba.c.execute( - "SELECT domain, software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial') ORDER BY rowid DESC" + "SELECT domain, software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial') AND (last_blocked IS NULL OR last_blocked < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_block"]] ) for blocker, software in fba.c.fetchall(): @@ -19,6 +19,8 @@ for blocker, software in fba.c.fetchall(): print("WARNING: blocker is now empty!") continue + fba.update_last_blocked(blocker) + if software == "pleroma": print("INFO: blocker:", blocker) try: -- 2.39.5