perf(backend): index the lookup columns and load order lines in batches
Order lines had no index on their order, orders none on their day/customer/status, and each line's product was loaded to tell a fee apart: with ~3000 orders Customers took ~2 s and Reports -> Days ~15 s. Migration 0038 adds the indexes (models carry index=True), Order.items loads with selectin, sales.lines looks the fee products up once, cancellations and prep-zones load their orders with the lines. Days 15 s -> 0.2 s (a month), customers 2 s -> 0.1 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,7 @@ class Reservation(Base):
|
||||
reserved_for = Column(UTCDateTime, nullable=False)
|
||||
|
||||
# Optional table assignment (assignable/editable later)
|
||||
table_id = Column(Integer, ForeignKey("tables.id"), nullable=True)
|
||||
table_id = Column(Integer, ForeignKey("tables.id"), nullable=True, index=True)
|
||||
|
||||
# Lifecycle: pending (confirmed, upcoming) | arrived | cancelled | no_show;
|
||||
# online requests (phase 3S, S.6) start as requested → pending (confirmed) | declined
|
||||
@@ -43,7 +43,7 @@ class Reservation(Base):
|
||||
total = Column(Float, nullable=True)
|
||||
online_price_diff = Column(Text, nullable=True) # services/online_check.py; NULL = matched
|
||||
fire_at = Column(UTCDateTime, nullable=True) # when the kitchen gets the food (set on confirming)
|
||||
order_id = Column(Integer, ForeignKey("orders.id"), nullable=True) # created at fire time
|
||||
order_id = Column(Integer, ForeignKey("orders.id"), nullable=True, index=True) # created at fire time
|
||||
response_note = Column(Text, nullable=True) # why it was declined / cancelled (the customer sees it)
|
||||
|
||||
created_at = Column(UTCDateTime, default=utcnow)
|
||||
|
||||
Reference in New Issue
Block a user