]> git.ipfire.org Git - dbl.git/commitdiff
reports: Update stats immediately after closing a report
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Jan 2026 11:43:00 +0000 (11:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Jan 2026 11:43:00 +0000 (11:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/lists.py
src/dnsbl/reports.py

index e67caa231647446ed84f6ed889735dd533078a65..f192edac904ead5dfe1af9cadcc18742fcc7cea1 100644 (file)
@@ -355,6 +355,39 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
 
                return self.backend.db.fetch_one(stmt)
 
+       def get_sources_by_domain(self, name):
+               """
+                       Returns all sources that list the given domain
+               """
+               stmt = (
+                       sqlmodel
+                       .select(
+                               sources.Source,
+                       )
+                       .select_from(
+                               domains.Domain,
+                       )
+                       .join(
+                               sources.Source,
+                               sources.Source.id == domains.Domain.source_id,
+                       )
+                       .where(
+                               # The domain must be on this list
+                               domains.Domain.list == self,
+
+                               # The name must match
+                               domains.Domain.name == name,
+
+                               # The domain cannot be removed
+                               domains.Domain.removed_at == None,
+
+                               # The domain must come from a source
+                               domains.Domain.source_id != None,
+                       )
+               )
+
+               return self.backend.db.fetch_as_set(stmt)
+
        # Total Domains
        total_domains : int = 0
 
index f50dc84da401b17807efd5b18c453ea43519bf83..ba93e7746da1a86fa253f2034e50a6b7b59b516d 100644 (file)
@@ -124,7 +124,7 @@ class Report(sqlmodel.SQLModel, database.BackendMixin, table=True):
 
        # Close!
 
-       def close(self, closed_by=None, accept=True):
+       def close(self, closed_by=None, accept=True, update_stats=True):
                """
                        Called when a moderator has made a decision
                """
@@ -154,3 +154,12 @@ class Report(sqlmodel.SQLModel, database.BackendMixin, table=True):
 
                # Log action
                log.info("Report %s has been closed by %s" % (self, self.closed_by))
+
+               # Update list stats
+               if update_stats:
+                       # Update stats for all sources that list this domain
+                       for source in self.list.get_sources_by_domain(self.name):
+                               source.update_stats()
+
+                       # Update the list's stats
+                       self.list.update_stats()