From b3011a99b77acc8b0cca678d3ce45924fb78d92a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 7 Aug 2023 01:25:19 +0200 Subject: [PATCH] Continued: - also store peer count for relays --- fba/commands.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index de1c8d1..d9a00fc 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -1888,6 +1888,7 @@ def fetch_relays(args: argparse.Namespace) -> int: logger.info("Checking %d relays ...", len(rows)) for row in rows: logger.debug("row[domain]='%s',row[software]='%s' ...", row["domain"], row["software"]) + peers = list() if not args.force and instances.is_recent(row["domain"]): logger.debug("row[domain]='%s' has been recently fetched - SKIPPED!", row["domain"]) continue @@ -1944,10 +1945,11 @@ def fetch_relays(args: argparse.Namespace) -> int: if domain == "": logger.debug("Empty domain after tidyup.domain() from origin='%s' - SKIPPED!", row["domain"]) continue - elif instances.is_registered(domain): - logger.debug("domain='%s' is already registered - SKIPPED!", domain) - continue - elif dict_helper.has_key(domains, "domain", domain): + elif domain not in peers: + logger.debug("Appending domain='%s' to peers list for relay='%s' ...", domain, row["domain"]) + peers.append(domain) + + if dict_helper.has_key(domains, "domain", domain): logger.debug("domain='%s' already added", domain) continue @@ -1987,10 +1989,11 @@ def fetch_relays(args: argparse.Namespace) -> int: if domain == "": logger.debug("Empty domain after tidyup.domain() from origin='%s' - SKIPPED!", row["domain"]) continue - elif instances.is_registered(domain): - logger.debug("domain='%s' is already registered - SKIPPED!", domain) - continue - elif dict_helper.has_key(domains, "domain", domain): + elif domain not in peers: + logger.debug("Appending domain='%s' to peers list for relay='%s' ...", domain, row["domain"]) + peers.append(domain) + + if dict_helper.has_key(domains, "domain", domain): logger.debug("domain='%s' already added", domain) continue @@ -2004,10 +2007,20 @@ def fetch_relays(args: argparse.Namespace) -> int: logger.debug("Updating last_instance_fetch for row[domain]='%s' ...", row["domain"]) instances.set_last_instance_fetch(row["domain"]) + + logger.info("Relay '%s' has %d peer(s) registered.", row["domain"], len(peers)) + instances.set_total_peers(row["domain"], peers) + + logger.debug("Flushing data for row[domain]='%s'", row["domain"]) instances.update_data(row["domain"]) - logger.info("Found %d domains to add ...", len(domains)) + logger.info("Checking %d domains ...", len(domains)) for row in domains: + logger.debug("row[domain]='%s',row[origin]='%s'", row["domain"], row["origin"]) + if instances.is_registered(row["domain"]): + logger.debug("row[domain]='%s' is already registered - SKIPPED!", row["domain"]) + continue + logger.info("Fetching row[domain]='%s',row[origin]='%s' ...", row["domain"], row["origin"]) federation.fetch_instances(row["domain"], row["origin"], None, inspect.currentframe().f_code.co_name) -- 2.39.5