]> git.ipfire.org Git - dbl.git/commitdiff
dnsbl: Show the number of domains on lists/sources
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 12:40:56 +0000 (12:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 12:40:56 +0000 (12:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/lists.py
src/dnsbl/sources.py
src/scripts/dnsbl.in

index 7c2e814618c3cb085ed21f1c04726c76692cec76..35dd94df57e87306fa88bff8c82477f4e1ba8394 100644 (file)
@@ -108,6 +108,32 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
        def __str__(self):
                return self.name
 
+       def __len__(self):
+               stmt = (
+                       sqlmodel
+                       .select(
+                               sqlmodel.func.count(
+                                       sqlmodel.func.distinct(
+                                               sources.SourceDomain.name,
+                                       ),
+                               ),
+                       )
+                       .select_from(
+                               sources.Source,
+                       )
+                       .join(
+                               sources.SourceDomain,
+                               sources.SourceDomain.source_id == sources.Source.id,
+                       )
+                       .where(
+                               sources.Source.list_id == self.id,
+                               sources.Source.deleted_at == None,
+                               sources.SourceDomain.removed_at == None,
+                       )
+               )
+
+               return self.backend.db.fetch_one(stmt)
+
        def __hash__(self):
                # Only hashable once the object has an ID
                if self.id is None:
index 9d9f5b8bc2f67e7f58790b9d4b866f2d37d142cd..54d460474a05de5ea0ef9e18a047a2e0c43d3021 100644 (file)
@@ -75,6 +75,23 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True):
        def __str__(self):
                return self.name
 
+       def __len__(self):
+               stmt = (
+                       sqlmodel
+                       .select(
+                               sqlmodel.func.count(),
+                       )
+                       .select_from(
+                               SourceDomain,
+                       )
+                       .where(
+                               SourceDomain.source == self,
+                               SourceDomain.removed_at == None,
+                       )
+               )
+
+               return self.backend.db.fetch_one(stmt)
+
        # ID
        id : int = sqlmodel.Field(primary_key=True)
 
index 303fadfc8e8bfd27f8c52813fc6d294dbc36d1cc..6a90e0f19255e4fcf2c82e7551c2d9c7a8bf255d 100644 (file)
@@ -188,6 +188,7 @@ class CLI(object):
                table.add_column(_("License"))
                table.add_column(_("Created At"))
                table.add_column(_("Created By"))
+               table.add_column(_("Listed Unique Domains"))
 
                # Show all lists
                for list in backend.lists:
@@ -197,6 +198,7 @@ class CLI(object):
                                list.license,
                                list.created_at.isoformat(),
                                list.created_by,
+                               "%s" % len(list),
                        )
 
                # Print the table
@@ -238,6 +240,7 @@ class CLI(object):
                table.add_row(_("License"), list.license)
                table.add_row(_("Created At"), list.created_at.isoformat())
                table.add_row(_("Created By"), list.created_by)
+               table.add_row(_("Listed Unique Domains"), "%s" % len(list))
 
                # Print list properties
                self.console.print(table)
@@ -249,6 +252,7 @@ class CLI(object):
                table.add_column(_("URL"))
                table.add_column(_("Created At"))
                table.add_column(_("Created_By"))
+               table.add_column(_("Listed Domains"))
 
                for source in list.sources:
                        table.add_row(
@@ -257,6 +261,7 @@ class CLI(object):
                                source.url,
                                source.created_at.isoformat(),
                                source.created_by,
+                               "%s" % len(source),
                        )
 
                # Print the sources