I'm collecting a lot of data from an API with an async function that cycles through a lot of data with a loop, I'm making about 100 requests and it takes around 8 seconds.
Are there any methods I can try to use, to speed up my script?
async function getplayerdata1() {
// Get current room
const response = await fetch(url)
let teams = await response.json()
let players = teams.players
let playerarray = players.length
for (var i = 0; i < playerarray; i++) {
// console.log(players[i]);
let username = players[i].username
let userid = players[i].id
// read user matches
const usermatch = await fetch(`https://api.site.com/user_profile/get_latest_matches?_=&id=${userid}&page=1`)
let matchlist = await usermatch.json()
let matchlistarray = matchlist.length
for (var ii = 0; ii < matchlistarray; ii++) {
// console.log(matchlist[ii])
// Read match stats
const matchlistResponse = await fetch(`https://api.site.com/match/get?_=&id=${matchlist[ii].id}`)
let matchlistResponsestats = await matchlistResponse.json()
// get 1st match stats
async function matchdata() {
if (matchlistResponsestats.players === null) {
const kills = 0
const deaths = 0
const headshot = 0
const headshotproc = 0
return [kills, deaths, headshotproc, headshotproc]
} else {
const filterArray = matchlistResponsestats.players[i]
console.log(filterArray)
console.log(filterArray.kills)
console.log(filterArray.deaths)
console.log(filterArray.headshots)
}
}
matchdata()
}
}
}
getplayerdata1()
}