diff --git a/lib/db-utils.js b/lib/db-utils.js index 29f5178..29a6311 100644 --- a/lib/db-utils.js +++ b/lib/db-utils.js @@ -470,11 +470,13 @@ module.exports = (srf, logger) => { } /* find all carrier entries that have an inbound gateway matching the source IP */ - /* Query both exact IP matches AND CIDR ranges to handle the case where + /* Query both exact IP matches AND CIDR ranges in parallel to handle the case where multiple accounts have configured the same carrier with different netmasks. The phone number lookup will disambiguate which account owns the call. */ - const [gwExact] = await pp.query(sqlSelectExactGatewayForSP, [req.source_address]); - const [gwCidr] = await pp.query(sqlSelectCIDRGatewaysForSP); + const [[gwExact], [gwCidr]] = await Promise.all([ + pp.query(sqlSelectExactGatewayForSP, [req.source_address]), + pp.query(sqlSelectCIDRGatewaysForSP) + ]); /* Merge both result sets - exact matches first, then CIDR ranges (already sorted by netmask DESC) */ const gw = [...gwExact, ...gwCidr];