From: Roland Häder Date: Sat, 20 May 2023 11:12:05 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8cf6ac6c4435fd2fad89a31093df3ef43849881d;p=fba.git Continued: - added last_blocked to reduce requering instances to often (be nice!) --- diff --git a/blocks_empty.db b/blocks_empty.db index af1c0a7..dc11b35 100644 Binary files a/blocks_empty.db and b/blocks_empty.db differ diff --git a/config.defaults.json b/config.defaults.json index 3578f7d..87f5b65 100644 --- a/config.defaults.json +++ b/config.defaults.json @@ -8,5 +8,6 @@ "bot_token": "", "bot_visibility": "unlisted", "slogan": "### Your footer slogan ###", - "recheck_instance": 3600 + "recheck_instance": 3600, + "recheck_block": 3600 } diff --git a/fba.py b/fba.py index 53ef74c..78f6b8b 100644 --- a/fba.py +++ b/fba.py @@ -31,6 +31,19 @@ def get_hash(domain: str) -> 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: