From 44ce8fa3e682086d81eed40d0d7a097b6600356d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 2 Jul 2023 09:41:39 +0200 Subject: [PATCH] Continued: - added column instances.total_blocks which stores total blocks found from instance - also expose it in /infos view --- blocks_empty.db | Bin 32768 -> 32768 bytes fba/boot.py | 1 + fba/commands.py | 11 ++++++++++- fba/models/instances.py | 13 +++++++++++++ templates/views/infos.html | 5 +++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/blocks_empty.db b/blocks_empty.db index 1df20d02238b5f3bb19c72b235f3c3e1ca33b8c9..c17a1b83412cdebc0db96508edf61b70fe29c29c 100644 GIT binary patch delta 101 zcmZo@U}|V!njkIsn}LCW1BhY3ZlaE{^lt_|?}@zJn;6*H3mN$4^1fp)c+Do9DAPF$w7?l;oEr=ENuEeVWlQ&nhH!*Ei int: else: logger.warning("Unknown software: blocker='%s',software='%s'", blocker, software) + logger.debug("Invoking instances.set_total_blocks(%s, %d) ...", blocker, len(blocking)) + instances.set_total_blocks(blocker, blocking) + logger.info("Checking %d entries from blocker='%s',software='%s' ...", len(blocking), blocker, software) blockdict = list() for block in blocking: @@ -1192,6 +1195,9 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: logger.info("Checking %d domains ...", len(rows)) for row in rows: logger.debug("Fetching peers from domain='%s',software='%s',nodeinfo_url='%s' ...", row["domain"], row["software"], row["nodeinfo_url"]) + if (args.all is None or not args.all) and instances.is_recent(row["domain"]) and args.domain is None and args.software is None: + logger.debug("row[domain]='%s' has been recently checked, args.all[]='%s' - SKIPPED!", row["domain"], type(args.all)) + continue blocking = list() if row["software"] == "pleroma": @@ -1212,6 +1218,9 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: else: logger.warning("Unknown sofware: domain='%s',software='%s'", row["domain"], row["software"]) + logger.debug("Invoking instances.set_total_blocks(%s, %d) ...", row["domain"], len(blocking)) + instances.set_total_blocks(row["domain"], blocking) + logger.info("Checking %d block(s) from domain='%s' ...", len(blocking), row["domain"]) obfuscated = 0 blockdict = list() @@ -1314,7 +1323,7 @@ def fetch_fedilist(args: argparse.Namespace) -> int: elif not utils.is_domain_wanted(domain): logger.warning("domain='%s' is not wanted - SKIPPED!", domain) continue - elif args.all is None or not args.all and instances.is_registered(domain): + elif (args.all is None or not args.all) and instances.is_registered(domain): logger.debug("domain='%s' is already registered, --all not specified: args.all[]='%s'", type(args.all)) continue elif instances.is_recent(domain): diff --git a/fba/models/instances.py b/fba/models/instances.py index 4ff0c18..59dc6b2 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -49,6 +49,8 @@ _pending = { "nodeinfo_url" : {}, # Found total peers "total_peers" : {}, + # Found total blocks + "total_blocks" : {}, # Last fetched instances "last_instance_fetch": {}, # Last updated @@ -396,6 +398,17 @@ def set_total_peers(domain: str, peers: list): _set_data("total_peers", domain, len(peers)) logger.debug("EXIT!") +def set_total_blocks(domain: str, blocks: list): + logger.debug("domain='%s',blocks()=%d - CALLED!", domain, len(blocks)) + domain_helper.raise_on(domain) + + if not isinstance(blocks, list): + raise ValueError(f"Parameter blocks[]='{type(blocks)}' is not 'list'") + + # Set timestamp + _set_data("total_blocks", domain, len(blocks)) + logger.debug("EXIT!") + def set_nodeinfo_url(domain: str, url: str): logger.debug("domain='%s',url='%s' - CALLED!", domain, url) domain_helper.raise_on(domain) diff --git a/templates/views/infos.html b/templates/views/infos.html index 2764c72..90b40e4 100644 --- a/templates/views/infos.html +++ b/templates/views/infos.html @@ -54,6 +54,11 @@ {{instance['total_peers']}} + + Total blocks: + {{instance['total_blocks']}} + + Has obfuscated block list: {% if instance['has_obfuscation']%}Yes{%elif not instance['has_obfuscation']%}No{%else%}-{%endif%} -- 2.39.5