Skip to content

Commit

Permalink
Merge pull request #866 from boxwise/improve-get-box-history-performance
Browse files Browse the repository at this point in the history
Improve query performance
  • Loading branch information
pylipp authored Jul 28, 2023
2 parents d6d3911 + 3cb3906 commit 1fed062
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ariadne import ObjectType

from ....authz import authorize
from ....models.definitions.shipment import Shipment
from ....models.definitions.shipment_detail import ShipmentDetail

shipment = ObjectType("Shipment")
Expand All @@ -10,7 +11,13 @@
@shipment.field("details")
def resolve_shipment_details(shipment_obj, _):
authorize(permission="shipment_detail:read")
return ShipmentDetail.select().where(ShipmentDetail.shipment == shipment_obj.id)
# Join with Shipment model, such that authorization in ShipmentDetail resolvers
# (detail.shipment.source_base_id) don't create additional DB queries
return (
ShipmentDetail.select(ShipmentDetail, Shipment)
.join(Shipment)
.where(ShipmentDetail.shipment == shipment_obj.id)
)


@shipment.field("sourceBase")
Expand Down Expand Up @@ -117,15 +124,13 @@ def resolve_shipment_detail_box(detail_obj, info):


@shipment_detail.field("sourceSize")
def resolve_shipment_detail_source_size(detail_obj, _):
authorize(permission="size:read")
return detail_obj.source_size
def resolve_shipment_detail_source_size(detail_obj, info):
return info.context["size_loader"].load(detail_obj.source_size_id)


@shipment_detail.field("targetSize")
def resolve_shipment_detail_target_size(detail_obj, _):
authorize(permission="size:read")
return detail_obj.target_size
def resolve_shipment_detail_target_size(detail_obj, info):
return info.context["size_loader"].load(detail_obj.target_size_id)


@shipment_detail.field("shipment")
Expand Down

0 comments on commit 1fed062

Please sign in to comment.