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:
@@ -10,14 +10,14 @@ class WasteLog(Base):
|
||||
__tablename__ = "waste_log"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
product_id = Column(Integer, ForeignKey("products.id"), nullable=False)
|
||||
product_id = Column(Integer, ForeignKey("products.id"), nullable=False, index=True)
|
||||
quantity = Column(Float, nullable=False) # supports decimals
|
||||
unit_cost_snapshot = Column(Float, nullable=True) # product's effective cost at log time
|
||||
total_cost = Column(Float, nullable=True) # unit_cost_snapshot * quantity
|
||||
reason = Column(String, nullable=False) # kitchen_error|dropped|expired|other
|
||||
reason_notes = Column(Text, nullable=True)
|
||||
logged_by_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
business_day_id = Column(Integer, ForeignKey("business_days.id"), nullable=True)
|
||||
business_day_id = Column(Integer, ForeignKey("business_days.id"), nullable=True, index=True)
|
||||
logged_at = Column(UTCDateTime, default=utcnow)
|
||||
|
||||
product = relationship("Product", foreign_keys=[product_id])
|
||||
|
||||
Reference in New Issue
Block a user