Skip to content

Commit

Permalink
[MDS-6097] Fix major project and NoW performance issues (#3193)
Browse files Browse the repository at this point in the history
* Revert bundle

* Remove permitees

* Revert "Revert bundle"

This reverts commit c99bdf2.

* Load permit amendment permittee_appointments lazily
  • Loading branch information
simensma-fresh authored Jul 24, 2024
1 parent d28a0f1 commit bb1ec20
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)')
Expand Down

0 comments on commit bb1ec20

Please sign in to comment.