I have a function that receives a user id and it searches the “orders” dataset and retrieves all the orders for that user and does some simple calculation on it and returns the result. when I call this function multiple times in a row with different user id each time, after 2nd or 3rd or 4th time (its not consistent, though I’ve seen it complete) it wont return anything and the rest of the script seems to just crash. Even if I remove the filters on it and run it, I still get similar result.
Here is an example of how I am calling the function.
await getOrderTotal(user1_id)
console.log("1 ok");
await getOrderTotal(user2_id)
console.log("2 ok");
await getOrderTotal(user3_id)
console.log("3 ok");
await getOrderTotal(user4_id)
console.log("4 ok);
Here is the function
async function getOrderTotal(userId){
return await wixData.query("Stores/Orders").eq("buyerInfo.id", userId).find()
.then( (result)=> {
console.log(result);
let sum = 0
if(result.length > 0){
for (let i = 0; i < result.length; i++) {
const total = result.items[i].totals.subtotal
sum += parseInt(total)
}
}
else{
return 0
}
return sum
}).catch((err) =>{
console.log(err);
return 0
})
}
Here is the output running the the program back to back with out making any changes. if you see the first time it only output “ok” 3 times and didn’t finish the program. second time it output “ok” 4 times and finished properly.
Thank you for your help!