diff --git a/modules/EcommerceFinance/Repositories/SmallPaymentWorkOrderMirrorRepository.php b/modules/EcommerceFinance/Repositories/SmallPaymentWorkOrderMirrorRepository.php index f5b6e80c..27e307ed 100644 --- a/modules/EcommerceFinance/Repositories/SmallPaymentWorkOrderMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/SmallPaymentWorkOrderMirrorRepository.php @@ -211,6 +211,9 @@ class SmallPaymentWorkOrderMirrorRepository $join->on('work_order_versions.woNo', '=', 'p.woNo'); }) ->join($workOrders . ' AS w', 'w.Id', '=', 'work_order_versions.Id') + // Match the leading columns of (woTypeId, woNo, Id), rather than + // rescanning all orders of this type for every payment-map row. + ->whereColumn('w.woNo', 'p.woNo') ->where('p.woTypeId', self::SMALL_PAYMENT_WORK_TYPE_ID) ->where('w.woTypeId', self::SMALL_PAYMENT_WORK_TYPE_ID); }