]> git.ipfire.org Git - dbl.git/commitdiff
lists: Store the total number of domains
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Dec 2025 16:34:34 +0000 (16:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Dec 2025 16:34:34 +0000 (16:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.sql
src/dnsbl/lists.py

index a1025951bfcae1ab2fc975298152e8daf54ecf36..74f924aa8e25d5de6ed7fd27c5755976682f8e4a 100644 (file)
@@ -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
 
index 44c47df7462b4507dd21a347fb3d3e11600586dd..0fab807885a7a6cb248a5ff1d68e57281f2b46f3 100644 (file)
@@ -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):