]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 2 Jul 2023 07:41:39 +0000 (09:41 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 2 Jul 2023 07:42:50 +0000 (09:42 +0200)
- added column instances.total_blocks which stores total blocks found from
  instance
- also expose it in /infos view

blocks_empty.db
fba/boot.py
fba/commands.py
fba/models/instances.py
templates/views/infos.html

index 1df20d02238b5f3bb19c72b235f3c3e1ca33b8c9..c17a1b83412cdebc0db96508edf61b70fe29c29c 100644 (file)
Binary files a/blocks_empty.db and b/blocks_empty.db differ
index 191321a1c613094e93112378ecc149172ead4c47..157d7a1bbcd096bb8159e2d8b3366fa6b979c895 100644 (file)
@@ -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 ###
index 6e57c7e0fa7cb7f9099ae1f914186543899d35e9..9f5b50962b882f9605d543f6c329782f5c343375 100644 (file)
@@ -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):
index 4ff0c188a80de48b628d38c309b5508403e55323..59dc6b222e3f4db721dedb3126fe678657b8aad8 100644 (file)
@@ -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)
index 2764c72b0b2ded7f17fe78e9e9571a971724cbd9..90b40e4921045ab51872e418c462bdf46e1ef25a 100644 (file)
         <td>{{instance['total_peers']}}</td>
     </tr>
 
+    <tr>
+        <td>Total blocks:</td>
+        <td>{{instance['total_blocks']}}</td>
+    </tr>
+
     <tr>
         <td>Has obfuscated block list:</td>
         <td>{% if instance['has_obfuscation']%}Yes{%elif not instance['has_obfuscation']%}No{%else%}-{%endif%}</td>