From 48dd7ebfcde1850e69ea547170c19c690beedf1b Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Sun, 18 Jan 2026 09:34:48 -0500 Subject: [PATCH] Parallelize independent exact IP and CIDR gateway database queries to reduce latency in inbound call routing (#234) --- lib/db-utils.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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];