sqlmodel
.select(
sqlmodel.func.count(
- sqlmodel.func.distinct(
- sources.SourceDomain.name,
- ),
+ self.__domains.c.name,
),
)
- .select_from(
- sources.Source,
- )
- .join(
- sources.SourceDomain,
- sources.SourceDomain.source_id == sources.Source.id,
- )
- .where(
- sources.Source.list_id == self.id,
- sources.Source.deleted_at == None,
- sources.SourceDomain.removed_at == None,
- )
)
return self.backend.db.fetch_one(stmt)
# Join it all together
return ".".join(e for e in s if e)
- @property
- def domains(self):
+ @functools.cached_property
+ def __domains(self):
"""
- Returns all domains that are on this list
+ A CTE to access all (active) domains on this list
"""
- stmt = (
+ cte = (
sqlmodel
.select(
- sources.SourceDomain.name,
+ sources.SourceDomain.name.label("name"),
)
.distinct(
sources.SourceDomain.name,
.order_by(
sources.SourceDomain.name,
)
+ .cte("domains")
+ )
+
+ return cte
+
+ @property
+ def domains(self):
+ """
+ Returns all domains that are on this list
+ """
+ stmt = (
+ sqlmodel
+ .select(
+ self.__domains.c.name,
+ )
)
return self.backend.db.fetch(stmt)