Further optimizations, improve counting to rely on backend DB

This commit is contained in:
2026-01-18 23:23:16 +01:00
parent 6ab9db4ed4
commit 4dde4225eb
7 changed files with 345 additions and 19 deletions

View File

@@ -48,6 +48,11 @@ class Consist(BaseModel):
def length(self):
return self.consist_item.filter(load=False).count()
@property
def loads_count(self):
"""Count of loads in this consist using database aggregation."""
return self.consist_item.filter(load=True).count()
def get_type_count(self):
return self.consist_item.filter(load=False).annotate(
type=models.F("rolling_stock__rolling_class__type__type")