fixed sort time

This commit is contained in:
HotSwapp
2025-10-14 07:56:13 -05:00
parent 9b2ce0d28f
commit 65e4995a5b
26 changed files with 99601 additions and 28 deletions

View File

@@ -21,7 +21,7 @@ from starlette.middleware.sessions import SessionMiddleware
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from sqlalchemy.orm import Session, joinedload
from sqlalchemy.orm import Session, selectinload, joinedload
from sqlalchemy import or_, and_, func as sa_func, select
from dotenv import load_dotenv
from starlette.middleware.base import BaseHTTPMiddleware
@@ -2709,8 +2709,8 @@ async def rolodex_list(
request.session["rolodex_sort"] = {"key": chosen_sort_key, "direction": chosen_sort_dir}
# Eager-load phones to avoid N+1 in template
query = db.query(Client).options(joinedload(Client.phones))
# Eager-load phones to avoid N+1 in template; use selectinload to avoid join explosion
query = db.query(Client).options(selectinload(Client.phones))
if q:
like = f"%{q}%"
@@ -2782,7 +2782,8 @@ async def rolodex_list(
query = query.order_by(*order_map[chosen_sort_key][chosen_sort_dir])
total: int = query.count()
# Count without ORDER BY for performance on SQLite
total: int = query.order_by(None).count()
total_pages: int = (total + page_size - 1) // page_size if total > 0 else 1
if page > total_pages:
page = total_pages