From: Michael Tremer Date: Wed, 10 Dec 2025 12:40:56 +0000 (+0000) Subject: dnsbl: Show the number of domains on lists/sources X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86426d1c6d8e8a76e083728e0fbe073949dd3851;p=dbl.git dnsbl: Show the number of domains on lists/sources Signed-off-by: Michael Tremer --- diff --git a/src/dnsbl/lists.py b/src/dnsbl/lists.py index 7c2e814..35dd94d 100644 --- a/src/dnsbl/lists.py +++ b/src/dnsbl/lists.py @@ -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: diff --git a/src/dnsbl/sources.py b/src/dnsbl/sources.py index 9d9f5b8..54d4604 100644 --- a/src/dnsbl/sources.py +++ b/src/dnsbl/sources.py @@ -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) diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in index 303fadf..6a90e0f 100644 --- a/src/scripts/dnsbl.in +++ b/src/scripts/dnsbl.in @@ -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