From: Roland Häder Date: Sun, 2 Jul 2023 07:41:39 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=44ce8fa3e682086d81eed40d0d7a097b6600356d;p=fba.git Continued: - added column instances.total_blocks which stores total blocks found from instance - also expose it in /infos view --- diff --git a/blocks_empty.db b/blocks_empty.db index 1df20d0..c17a1b8 100644 Binary files a/blocks_empty.db and b/blocks_empty.db differ diff --git a/fba/boot.py b/fba/boot.py index 191321a..157d7a1 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -72,6 +72,7 @@ def init_parser(): ) parser.add_argument("--domain", help="Instance name (aka. domain)") parser.add_argument("--software", help="Name of software, e.g. 'lemmy'") + parser.add_argument("--all", action="store_true", help="Include also already existing instances, otherwise only new are checked") parser.set_defaults(command=commands.recheck_obfuscation) ### Fetch blocks from registered instances or given ### diff --git a/fba/commands.py b/fba/commands.py index 6e57c7e..9f5b509 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -298,6 +298,9 @@ def fetch_blocks(args: argparse.Namespace) -> 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%}