Files
bonaminandClaude Opus 5.5 618fef53ef 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>
2026-11-20 14:42:09 +02:00

51 lines
2.1 KiB
Python

from sqlalchemy import Column, Integer, String, ForeignKey, Text, Boolean
from core.timeutil import UTCDateTime, utcnow
from sqlalchemy.orm import relationship
from database import Base
class QuickMessageTemplate(Base):
"""Manager-configurable quick message templates."""
__tablename__ = "quick_message_templates"
id = Column(Integer, primary_key=True, index=True)
body = Column(String, nullable=False)
sort_order = Column(Integer, default=0, nullable=False)
is_active = Column(Boolean, default=True, nullable=False)
created_at = Column(UTCDateTime, default=utcnow)
class StaffMessage(Base):
"""A message sent from a manager or KDS to one or more waiters."""
__tablename__ = "staff_messages"
id = Column(Integer, primary_key=True, index=True)
sender_id = Column(Integer, ForeignKey("users.id"), nullable=False)
body = Column(Text, nullable=False)
# JSON arrays stored as text: "[1,2,3]" for waiter ids, "[5,6]" for table ids
target_waiter_ids = Column(Text, nullable=False, default="[]")
table_ids = Column(Text, nullable=False, default="[]")
# message_type: 'manager' | 'kds_order_done' | 'kds_item_done' | 'kds_call_order' | 'kds_call_general'
message_type = Column(String, nullable=False, default="manager")
# kds_zone: display name of the prep zone that sent this (e.g. "Κουζίνα")
kds_zone = Column(String, nullable=True)
created_at = Column(UTCDateTime, default=utcnow)
sender = relationship("User", foreign_keys=[sender_id])
acks = relationship("StaffMessageAck", back_populates="message", cascade="all, delete-orphan")
class StaffMessageAck(Base):
"""Acknowledgement by a specific waiter for a specific message."""
__tablename__ = "staff_message_acks"
id = Column(Integer, primary_key=True, index=True)
message_id = Column(Integer, ForeignKey("staff_messages.id"), nullable=False, index=True)
waiter_id = Column(Integer, ForeignKey("users.id"), nullable=False)
acked_at = Column(UTCDateTime, default=utcnow)
message = relationship("StaffMessage", back_populates="acks")
waiter = relationship("User")