Parallelize independent exact IP and CIDR gateway database queries to reduce latency in inbound call routing (#234)

This commit is contained in:
Dave Horton
2026-01-18 09:34:48 -05:00
committed by GitHub
parent 678fe9d9a8
commit 48dd7ebfcd

View File

@@ -470,11 +470,13 @@ module.exports = (srf, logger) => {
} }
/* find all carrier entries that have an inbound gateway matching the source IP */ /* 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. multiple accounts have configured the same carrier with different netmasks.
The phone number lookup will disambiguate which account owns the call. */ The phone number lookup will disambiguate which account owns the call. */
const [gwExact] = await pp.query(sqlSelectExactGatewayForSP, [req.source_address]); const [[gwExact], [gwCidr]] = await Promise.all([
const [gwCidr] = await pp.query(sqlSelectCIDRGatewaysForSP); pp.query(sqlSelectExactGatewayForSP, [req.source_address]),
pp.query(sqlSelectCIDRGatewaysForSP)
]);
/* Merge both result sets - exact matches first, then CIDR ranges (already sorted by netmask DESC) */ /* Merge both result sets - exact matches first, then CIDR ranges (already sorted by netmask DESC) */
const gw = [...gwExact, ...gwCidr]; const gw = [...gwExact, ...gwCidr];