From 3ad5eb0b8994ddecadc7b7c05b2241c5d4cb0ae7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 27 Nov 2023 22:47:55 +0100 Subject: [PATCH] Continued: - rewrote so all parameters for command fetch_blocks() can have parameter --force - added parameter --only-none --- fba/boot.py | 1 + fba/commands.py | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/fba/boot.py b/fba/boot.py index 9e8e91c..93d4546 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -89,6 +89,7 @@ def init_parser(): parser.set_defaults(command=commands.fetch_blocks) parser.add_argument("--domain", help="Instance name (aka. domain)") parser.add_argument("--software", help="Name of software, e.g. 'lemmy'") + parser.add_argument("--only-none", action="store_true", help="Checks only entries which has never been checked.") parser.add_argument("--force", action="store_true", help="Forces update of data, no matter what.") ### Fetch blocks from chaos.social ### diff --git a/fba/commands.py b/fba/commands.py index 7886d37..faabb9e 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -292,16 +292,15 @@ def fetch_blocks(args: argparse.Namespace) -> int: database.cursor.execute( "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software = ? AND nodeinfo_url IS NOT NULL ORDER BY total_blocks DESC, last_response_time ASC, last_updated ASC", [args.software] ) - elif args.force: - # Re-check all - logger.debug("Re-checking all instances ...") + elif args.only_none: + # Check only entries with total_blocked=None database.cursor.execute( - "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey') AND nodeinfo_url IS NOT NULL ORDER BY total_blocks DESC, last_response_time ASC, last_updated ASC" + "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey') AND total_blocks IS NULL ORDER BY total_blocks DESC, last_response_time ASC, last_updated ASC" ) else: # Re-check after "timeout" (aka. minimum interval) database.cursor.execute( - "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey') AND (last_blocked IS NULL OR last_blocked < ?) AND nodeinfo_url IS NOT NULL ORDER BY total_blocks DESC, last_response_time ASC, last_updated ASC", [time.time() - config.get("recheck_block")] + "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey') AND nodeinfo_url IS NOT NULL ORDER BY total_blocks DESC, last_response_time ASC, last_updated ASC" ) rows = database.cursor.fetchall() @@ -312,6 +311,9 @@ def fetch_blocks(args: argparse.Namespace) -> int: if not domain_helper.is_wanted(blocker): logger.warning("blocker='%s' is not wanted - SKIPPED!", blocker) continue + elif instances.is_recent(blocker) and not args.force: + logger.debug("blocker='%s' has been recently accessed - SKIPPED!", blocker) + continue logger.debug("Setting last_blocked,has_obfuscation=false for blocker='%s' ...", blocker) instances.set_last_blocked(blocker) -- 2.39.2