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>
16 lines
688 B
Python
16 lines
688 B
Python
from sqlalchemy import Column, ForeignKey, Integer, String
|
|
|
|
from core.timeutil import UTCDateTime, utcnow
|
|
from database import Base
|
|
|
|
|
|
class PhoneCall(Base):
|
|
"""An incoming call the venue's phone system reported (caller ID, plan step 3.5)."""
|
|
__tablename__ = "phone_calls"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
at = Column(UTCDateTime, default=utcnow, nullable=False, index=True)
|
|
number = Column(String, nullable=False) # as the phone system sent it
|
|
ext = Column(String, nullable=True) # the extension that was dialled
|
|
customer_id = Column(Integer, ForeignKey("customers.id", ondelete="SET NULL"), nullable=True, index=True)
|