But we need the if clause as we only execute a plethora of code when this isn’t a duplicate firing of the remote call.
Now my understanding of the findAndModify is that it’s a Swiss Army knife, with the remove, update or upsert option. Not sure what it delivers back on upsert but it’s anyway just executing the two operations that is in our code anyways, so I see no speed improvement.
Sure, it’s called inside the loop (which has the remote call at the end) via:
// delay loop execution
await addDelay();
The function itself is to avoid violating the T&C of the 3rd party service (excessive usage) that we’re working with:
// promise based function to stop for loops or any other execution
const addDelay = async function () {
// generates a random wait period between min and max milliseconds
let { minDelay, maxDelay } = Meteor.settings.public;
return new Promise((resolve) => setTimeout(resolve, Math.floor(Math.random() * (maxDelay - minDelay + 1) + minDelay)));
};
Was it the same user in both cases or different? Can you see the browser they were using and see if there’s any clue in that? I’m wondering if there’s some buggy promise implementation out there?
Perhaps you call this code via a method on the client?
If yes, you probably need to scope parts of it with Meteor.isServer or the method simulation will run and call remote.call and once that passes (can happen within 2ms) the ‘actual call’ will run, resulting in the 2 sequential calls that you experience.
Hi Satya, we do have separate servers for frontend and backend. The main reason is to scale them independently, as the frontend server can take a lot more users than backend (our app is very compute heavy).