I developed a service with Nest JS which calls a third party api in order to get the status related to some pull requests in Azure DevOps. The logic works as follows: I provide an array with links to a function, then I use a for loop to a block of code which will take care of getting the url from the array and build the http request and call the api to retrieve the status(using the axios implementation in Nest JS). It works as an async operation which sequentially makes each request. But it is taking relatively too long(about 160s to get 1000 requests). Does someone have a suggestion in how to improve the speed of execution?
async getAzureStatus(urlAdjusted) {
const updatedPRStatus = [process.env.EXCEL_COLUMN_PR_STATUS_HEADER];
for(let counter = 1; counter < urlAdjusted.length; counter++) {
if( urlAdjusted[counter] == 'Not needed')
{
updatedPRStatus.push('Not needed');
}
else
{
const config =
{
headers:
{
Authorization: process.env.AUTHENTICATION_KEY,
},
};
try
{
const response = await lastValueFrom(this.httpService.get(urlAdjusted[counter], config));
updatedPRStatus.push(response.data['status']);
} catch(error)
{
console.log('error retrieving pr number ' + counter );
updatedPRStatus.push('Could not get any data');
}
}
}
return updatedPRStatus;
}