06/08 Optimize queries with indexes

This commit is contained in:
2026-06-08 14:45:04 -04:00
parent 9eec6ff94a
commit a548cc0b8e
5 changed files with 98 additions and 2 deletions
+7 -1
View File
@@ -24,6 +24,7 @@ from app.models.notification import (
)
from app.utils.audit import log_action, ACTION_CREATE, ACTION_UPDATE, ACTION_DELETE, ACTION_EXPORT
from app.utils.scope import get_customer_scope, get_inspector_scope
from sqlalchemy.orm import joinedload
bp = Blueprint('inspections', __name__, url_prefix='/inspections')
@@ -198,7 +199,12 @@ def _validate_required(form_fields, responses):
@login_required
def index():
page = request.args.get('page', 1, type=int)
q = Inspection.query.order_by(Inspection.inspection_date.desc())
q = Inspection.query.options(
joinedload(Inspection.facility),
joinedload(Inspection.template),
joinedload(Inspection.inspector),
joinedload(Inspection.area),
).order_by(Inspection.inspection_date.desc())
if current_user.role == 'inspector':
fids = get_inspector_scope(current_user)