Skip to content

Commit

Permalink
refactor: address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed Apr 2, 2024
1 parent 1794cf4 commit 8bff9d9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export const makeGeocoderRequests = async (
const peliasQSP = { ...event.queryStringParameters }
delete peliasQSP.layers

// Run both requests in parallel
let responses: FeatureCollection[] = await Promise.all(
// Run all requests in parallel
const uncheckedResponses: FeatureCollection[] = await Promise.all(
geocoders.map((geocoder) =>
cachedGeocoderRequest(getGeocoder(geocoder), apiMethod, {
...convertQSPToGeocoderArgs(event.queryStringParameters),
Expand All @@ -99,8 +99,9 @@ export const makeGeocoderRequests = async (
)
)

responses = await Promise.all(
responses.map(async (response, index) => {
// Check if responses are satisfactory, and re-do them if needed
const responses = await Promise.all(
uncheckedResponses.map(async (response, index) => {
// If backup geocoder is present, and the returned results are garbage, use the backup geocoder
// if one is configured. This request will not be cached
if (
Expand All @@ -111,7 +112,6 @@ export const makeGeocoderRequests = async (
)
) {
const backupGeocoder = getGeocoder(backupGeocoders[index])
console.log('backup geocoder used!')
return await backupGeocoder[apiMethod](
convertQSPToGeocoderArgs(event.queryStringParameters)
)
Expand All @@ -128,6 +128,7 @@ export const makeGeocoderRequests = async (
if (idx === 0) return cur
return mergeResponses({ customResponse: cur, primaryResponse: prev })
},
// TODO: clean this reducer up. See https://github.com/ibi-group/pelias-stitch/pull/28#discussion_r1547582739
{ features: [], type: 'FeatureCollection' }
)

Expand Down

0 comments on commit 8bff9d9

Please sign in to comment.