From 93254222d2793d22d6901c048f1b7d64899b1858 Mon Sep 17 00:00:00 2001 From: Simen Fivelstad Smaaberg <66635118+simensma-fresh@users.noreply.github.com> Date: Wed, 24 Jul 2024 00:05:49 +0000 Subject: [PATCH] Load permit amendment permittee_appointments lazily --- .../models/permit_amendment.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/services/core-api/app/api/mines/permits/permit_amendment/models/permit_amendment.py b/services/core-api/app/api/mines/permits/permit_amendment/models/permit_amendment.py index c9e5157f31..0835adbce6 100644 --- a/services/core-api/app/api/mines/permits/permit_amendment/models/permit_amendment.py +++ b/services/core-api/app/api/mines/permits/permit_amendment/models/permit_amendment.py @@ -1,22 +1,23 @@ -from datetime import datetime, date - import uuid +from datetime import date, datetime +from app.api.constants import * +from app.api.mines.permits.permit_amendment.models.permit_amendment_document import ( + PermitAmendmentDocument, +) +from app.api.mines.permits.permit_conditions.models.permit_conditions import ( + PermitConditions, +) +from app.api.utils.models_mixins import AuditMixin, Base, SoftDeleteMixin +from app.api.verifiable_credentials.aries_constants import IssueCredentialIssuerState +from app.extensions import db from sqlalchemy.dialects.postgresql import UUID -from sqlalchemy.orm import validates from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.hybrid import hybrid_property - +from sqlalchemy.orm import validates from sqlalchemy.schema import FetchedValue -from app.extensions import db - -from app.api.mines.permits.permit_amendment.models.permit_amendment_document import PermitAmendmentDocument -from app.api.mines.permits.permit_conditions.models.permit_conditions import PermitConditions -from app.api.verifiable_credentials.aries_constants import IssueCredentialIssuerState from . import permit_amendment_status_code, permit_amendment_type_code -from app.api.utils.models_mixins import SoftDeleteMixin, AuditMixin, Base -from app.api.constants import * class PermitAmendment(SoftDeleteMixin, AuditMixin, Base): @@ -95,9 +96,11 @@ class PermitAmendment(SoftDeleteMixin, AuditMixin, Base): order_by='desc(PartyVerifiableCredentialMinesActPermit.update_timestamp)') mines_act_permit_vc_locked = association_proxy("permit", 'mines_act_permit_vc_locked') + # Note: This relationship is lazy loaded on purpose to avoid being loaded unless absolutely necessary + # a selectin or joined query here causes performance issues due to the nested structure of NoW and Major Projects. permittee_appointments = db.relationship( "MinePartyAppointment", - lazy="selectin", + lazy="select", secondary='permit', secondaryjoin='and_(foreign(Permit.permit_id) == remote(MinePartyAppointment.permit_id))', order_by='desc(MinePartyAppointment.start_date)')