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

42 lines
1.8 KiB
Python

from sqlalchemy import Column, Integer, String, Boolean, Float, ForeignKey
from sqlalchemy.orm import relationship
from database import Base
class TableGroup(Base):
__tablename__ = "table_groups"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False, unique=True)
prefix = Column(String, nullable=True)
sort_order = Column(Integer, default=0)
color = Column(String, nullable=True)
tables = relationship("Table", back_populates="group")
waiter_zones = relationship("WaiterZone", back_populates="group")
class Table(Base):
__tablename__ = "tables"
id = Column(Integer, primary_key=True, index=True)
number = Column(Integer, nullable=False)
label = Column(String, nullable=True)
group_id = Column(Integer, ForeignKey("table_groups.id"), nullable=True, index=True)
is_active = Column(Boolean, default=True, nullable=False)
seat_count = Column(Integer, nullable=True)
# its place on a floor plan (6.8, D-31; models/floor_plan.py): floor_x / floor_y = its centre
plan_id = Column(Integer, ForeignKey("floor_plans.id", ondelete="SET NULL"), nullable=True, index=True)
floor_x = Column(Float, nullable=True)
floor_y = Column(Float, nullable=True)
width = Column(Float, nullable=True)
height = Column(Float, nullable=True)
rotation = Column(Float, nullable=True)
shape = Column(String, nullable=True) # round | square | long
# the table's QR code (phase 3S, S.7): a random token in the QR menu link; the cloud gets
# only its sha256 (services/table_qr.py). A new token makes the printed code useless.
qr_token = Column(String, nullable=True, unique=True)
group = relationship("TableGroup", back_populates="tables")
orders = relationship("Order", back_populates="table")