From: Michael Tremer Date: Fri, 9 Jan 2026 13:52:51 +0000 (+0000) Subject: lists: Store stats about subsumed lists X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=337c6902f28c89b6c008e03e19863ec6ef105d23;p=dbl.git lists: Store stats about subsumed lists Signed-off-by: Michael Tremer --- diff --git a/src/database.sql b/src/database.sql index 9b9dabb..df50992 100644 --- a/src/database.sql +++ b/src/database.sql @@ -2,7 +2,7 @@ -- PostgreSQL database dump -- -\restrict zZebqk0H6Bn3b2lu7FY4z6lPZCN2XBuuNpQTisoH3Wz8jUXzJwWewQlrEzRq9r7 +\restrict 80aOA5yV31bCsEeXZQpelpLcW1cJfgnz27c1dg1p4ydlMSFyDUMztrDG4WdSfbB -- Dumped from database version 17.6 (Debian 17.6-0+deb13u1) -- Dumped by pg_dump version 17.6 (Debian 17.6-0+deb13u1) @@ -169,7 +169,8 @@ CREATE TABLE public.list_stats ( id integer NOT NULL, list_id integer NOT NULL, ts timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, - total_domains integer NOT NULL + total_domains integer NOT NULL, + subsumed_domains integer DEFAULT 0 NOT NULL ); @@ -210,7 +211,8 @@ CREATE TABLE public.lists ( description text, total_domains integer DEFAULT 0 NOT NULL, pending_reports integer DEFAULT 0 NOT NULL, - priority integer DEFAULT 0 NOT NULL + priority integer DEFAULT 0 NOT NULL, + subsumed_domains integer DEFAULT 0 NOT NULL ); @@ -639,5 +641,5 @@ ALTER TABLE ONLY public.sources -- PostgreSQL database dump complete -- -\unrestrict zZebqk0H6Bn3b2lu7FY4z6lPZCN2XBuuNpQTisoH3Wz8jUXzJwWewQlrEzRq9r7 +\unrestrict 80aOA5yV31bCsEeXZQpelpLcW1cJfgnz27c1dg1p4ydlMSFyDUMztrDG4WdSfbB diff --git a/src/dnsbl/lists.py b/src/dnsbl/lists.py index f25924b..6dc4d9c 100644 --- a/src/dnsbl/lists.py +++ b/src/dnsbl/lists.py @@ -433,7 +433,10 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True): return self.backend.db.fetch_as_set(stmt) # Total Domains - total_domains : int = 0 + total_domains: int = 0 + + # Subsumed Domains + subsumed_domains: int = 0 # Delete! @@ -483,11 +486,33 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True): # Store the number of total domains self.total_domains = self.backend.db.fetch_one(stmt) + # Store the number of subsumed domains + self.subsumed_domains = self.backend.db.fetch_one( + sqlmodel + .select( + sqlmodel.func.count(), + ) + .where( + # Select only domains from this list + domains.Domain.list == self, + + # Only select domains that should be blocked + domains.Domain.block == True, + + # Ignore domains that have been removed + domains.Domain.removed_at == None, + + # Only count subsumed domains + domains.Domain.subsumed == True, + ) + ) + # Store the stats history self.backend.db.insert( ListStats, - list = self, - total_domains = self.total_domains, + list = self, + total_domains = self.total_domains, + subsumed_domains = self.subsumed_domains, ) # Export! @@ -845,3 +870,6 @@ class ListStats(sqlmodel.SQLModel, table=True): # Total Domains total_domains: int + + # Subsumed Domains + subsumed_domains: int = 0 diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in index 2d88038..f5b996d 100644 --- a/src/scripts/dnsbl.in +++ b/src/scripts/dnsbl.in @@ -328,6 +328,7 @@ class CLI(object): table.add_row(_("Created At"), list.created_at.isoformat()) table.add_row(_("Created By"), list.created_by) table.add_row(_("Listed Unique Domains"), babel.numbers.format_decimal(len(list))) + table.add_row(_("Subsumed Domains"), babel.numbers.format_decimal(list.subsumed_domains)) # Print list properties self.console.print(table)