From: Michael Tremer Date: Mon, 29 Dec 2025 16:34:34 +0000 (+0000) Subject: lists: Store the total number of domains X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70bc06734ee4cb416c04df23480bb428232be8ae;p=dbl.git lists: Store the total number of domains Signed-off-by: Michael Tremer --- diff --git a/src/database.sql b/src/database.sql index a102595..74f924a 100644 --- a/src/database.sql +++ b/src/database.sql @@ -2,7 +2,7 @@ -- PostgreSQL database dump -- -\restrict pljGpSA3LcghRNp7l8VhB9577BShEv8iwmjIVnsBJjUDBiyXWHsvzLrsdBLd4g5 +\restrict pZMXIfcg6Z3bqZxjE81zS0hcdaYCb5acZyYejnUVfbZS81irldi5kwkQVbA7Prg -- Dumped from database version 17.6 (Debian 17.6-0+deb13u1) -- Dumped by pg_dump version 17.6 (Debian 17.6-0+deb13u1) @@ -48,7 +48,8 @@ CREATE TABLE public.lists ( deleted_by text, license text NOT NULL, updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, - description text + description text, + total_domains integer DEFAULT 0 NOT NULL ); @@ -295,5 +296,5 @@ ALTER TABLE ONLY public.sources -- PostgreSQL database dump complete -- -\unrestrict pljGpSA3LcghRNp7l8VhB9577BShEv8iwmjIVnsBJjUDBiyXWHsvzLrsdBLd4g5 +\unrestrict pZMXIfcg6Z3bqZxjE81zS0hcdaYCb5acZyYejnUVfbZS81irldi5kwkQVbA7Prg diff --git a/src/dnsbl/lists.py b/src/dnsbl/lists.py index 44c47df..0fab807 100644 --- a/src/dnsbl/lists.py +++ b/src/dnsbl/lists.py @@ -113,16 +113,7 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True): return True def __len__(self): - stmt = ( - sqlmodel - .select( - sqlmodel.func.count( - self.__domains.c.name, - ), - ) - ) - - return self.backend.db.fetch_one(stmt) + return self.total_domains def __hash__(self): # Only hashable once the object has an ID @@ -264,6 +255,9 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True): return self.backend.db.fetch(stmt) + # Total Domains + total_domains : int + # Delete! def delete(self, deleted_by): @@ -293,6 +287,22 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True): if updated: self.updated_at = sqlmodel.func.current_timestamp() + # Update the stats + self.__update_stats() + + def __update_stats(self): + stmt = ( + sqlmodel + .select( + sqlmodel.func.count( + self.__domains.c.name, + ), + ) + ) + + # Store the number of total domains + self.total_domains = self.backend.db.fetch_one(stmt) + # Export! def export(self, f, format, **kwargs):