]> git.ipfire.org Git - dbl.git/commitdiff
lists: Remove dead domains from the exports again
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Feb 2026 12:59:38 +0000 (12:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Feb 2026 12:59:38 +0000 (12:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dbl/lists.py

index 787f77045c1966ff0e4a278a27a28a0ad330136d..80edaa48d4064e44077ec6f07649258d7d813981 100644 (file)
@@ -798,6 +798,27 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
                        ),
                )
 
+               # Fetch all dead domains
+               dead_names = await self.backend.db.fetch_as_set(
+                       sqlmodel
+                       .select(
+                               domains.Domain.name,
+                       )
+                       .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 select domains confirmed dead
+                               domains.Domain.dead == True,
+                       ),
+               )
+
                # Fetch all potentially blocked domains
                names = await self.backend.db.fetch_as_set(
                        sqlmodel
@@ -813,13 +834,6 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
 
                                # Ignore domains that have been removed
                                domains.Domain.removed_at == None,
-
-                               # Only select domains that are not dead
-                               # or have not been checked, yet.
-                               sqlmodel.or_(
-                                       domains.Domain.dead == None,
-                                       domains.Domain.dead == False,
-                               ),
                        ),
                )
 
@@ -829,12 +843,17 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
                # Collect all names that are redundant
                redundant_names = set()
 
-               # List everything that isn't whitelisted
-               if whitelisted:
-                       for name in names:
+               # Walk through all names
+               for name in names:
+                       # De-list everything that is whitelisted
+                       if whitelisted:
                                if util.is_name_in(name, whitelisted):
                                        delisted_names.add(name)
 
+                       # Delist everything that is dead
+                       if name in dead_names:
+                               delisted_names.add(name)
+
                # Find any redundant domains
                for name in names:
                        if util.is_parent_in(name, names):