]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 6 Aug 2023 23:25:19 +0000 (01:25 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 6 Aug 2023 23:28:12 +0000 (01:28 +0200)
- also store peer count for relays

fba/commands.py

index de1c8d1b734d75d4cdcc3f12e985bcecddb1c699..d9a00fc031df33c6b5d04898f2992a0db1b725b5 100644 (file)
@@ -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)