From 5631a511ebb7f092d9f8c35de11280a71ee9627b Mon Sep 17 00:00:00 2001 From: jakeross Date: Sun, 7 Dec 2025 15:06:53 -0700 Subject: [PATCH] feat: update type hints for clarity and comment out lazy loading in relationships for performance testing --- api/geospatial.py | 5 ++--- db/thing.py | 18 +++++++++--------- services/query_helper.py | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/api/geospatial.py b/api/geospatial.py index f718b41ed..61bdc3425 100644 --- a/api/geospatial.py +++ b/api/geospatial.py @@ -65,7 +65,7 @@ async def get_project_area( user: viewer_dependency, session: session_dependency, group_id: int ) -> FeatureCollectionResponse: - group = simple_get_by_id(session, Group, group_id) + group: Group = simple_get_by_id(session, Group, group_id) if not group.project_area: raise HTTPException(status_code=404, detail="Group has no project area") @@ -99,8 +99,6 @@ def get_feature_collection( Endpoint to retrieve a GeoJSON FeatureCollection. """ - things = get_thing_features(session, thing_type, group) - def make_feature_dict(thing, geometry, elevation, *other): geometry = json.loads(geometry) geometry["coordinates"].append(elevation) @@ -115,6 +113,7 @@ def make_feature_dict(thing, geometry, elevation, *other): "geometry": geometry, } + things = get_thing_features(session, thing_type, group) features = [make_feature_dict(*item) for item in things] return { diff --git a/db/thing.py b/db/thing.py index 286372242..303289de0 100644 --- a/db/thing.py +++ b/db/thing.py @@ -207,7 +207,7 @@ class Thing( cascade="all, delete-orphan", passive_deletes=True, order_by="LocationThingAssociation.effective_start.desc()", - lazy="joined", + # lazy="joined", ) contact_associations = relationship( @@ -254,7 +254,7 @@ class Thing( back_populates="thing", cascade="all, delete-orphan", passive_deletes=True, - lazy="joined", + # lazy="joined", ) well_casing_materials: Mapped[List["WellCasingMaterial"]] = relationship( @@ -262,7 +262,7 @@ class Thing( back_populates="thing", cascade="all, delete-orphan", passive_deletes=True, - lazy="joined", + # lazy="joined", ) links: Mapped[List["ThingIdLink"]] = relationship( @@ -270,7 +270,7 @@ class Thing( back_populates="thing", cascade="all, delete-orphan", passive_deletes=True, - lazy="joined", + # lazy="joined", ) # One-To-Many: A Thing (well) can have multiple measuring points over time. @@ -279,7 +279,7 @@ class Thing( back_populates="thing", cascade="all, delete-orphan", passive_deletes=True, - lazy="joined", + # lazy="joined", ) monitoring_frequencies: Mapped[List["MonitoringFrequencyHistory"]] = relationship( @@ -287,7 +287,7 @@ class Thing( back_populates="thing", cascade="all, delete-orphan", passive_deletes=True, - lazy="joined", + # lazy="joined", ) # One-To-Many: A Thing can be associated with many AquiferSystems via the ThingAquiferAssociation join table. @@ -296,7 +296,7 @@ class Thing( back_populates="thing", cascade="all, delete-orphan", passive_deletes=True, - lazy="joined", + # lazy="joined", ) # Many-To-Many: A Thing can penetrate many GeologicFormations. @@ -306,7 +306,7 @@ class Thing( back_populates="thing", cascade="all, delete-orphan", passive_deletes=True, - lazy="joined", + # lazy="joined", ) ) @@ -349,7 +349,7 @@ class Thing( search_vector = Column(TSVectorType("name")) # for temporary backwards compatibility - well_construction_notes = mapped_column(String(1000), nullable=True) + # well_construction_notes = mapped_column(String(1000), nullable=True) @property def current_location(self): diff --git a/services/query_helper.py b/services/query_helper.py index 970ad1720..aea7d81e6 100644 --- a/services/query_helper.py +++ b/services/query_helper.py @@ -88,7 +88,7 @@ def simple_get_by_name(session, table, name) -> object | None: def simple_get_by_id( session: Session, table: DeclarativeBase, item_id: int -) -> object | None: +) -> DeclarativeBase | None: """ Helper function to get a record by ID from the database. """