I have this weird issue that sometimes, if a user clicks on a button the backend function call gets triggered multiple times.
This is the frontend code:
$w ( ‘#button’ ). onClick ( async function () {
$w ( ‘#button’ ). disable ();
let sucess = await check_data (parameters);
set_state (success)
$w ( ‘#button’ ). enable ();
});
The Backend function check_data is a pretty expensive function which may take up to a minute to run.
Did anyone experience something similar or could point me to my mistake?
Sincerely
Julien
How do you know check_data() is being triggered multiple times? I only see you calling it once. Have you tried a console.log() statement in the onClick() event handler to see when the button is clicked?
Where do you set parameters ? Also, what is set_state()? What does it do, and when?
What does check_data() do? You should add a console.log() statement to check_data() to see when and if it’s being called.
Hey, thank you for your reply.
Parameters is set in this function. It is just a JSON that is collected from user inputs from the form the user is about to submit. I removed it in the example since it’s rather long and not relevant to the issue.
set_state is also just a basic function which just notifies the user if the submit was successful. This also runs just once.
The function check_data runs a validation test on a file which the user uploaded previously. After this check is done the file gets deleted and writes the results to the database. If this error occurs I see that the validation test ran on the same file multiple times with the db entries written within the same second. Also this does not happen every time, actually most of the time it works just right only sometimes there are up to five repeated entries.
Have you tried a console.log() statement in the onClick() event handler to see when the button is clicked?
Yeah, the button click works as expected. There is just one console message printed.
What does check_data() do? You should add a console.log() statement to check_data() to see when and if it’s being called.
I did but could not replicate the behaviour in the sandbox.
@juliendavid Impossible to know what’s going on. You need to step up your debugging game. You should use the Site Monitoring tools so that you can see exactly what’s happening.
@yisrael-wix Thank you very much.
I did not know about the site monitoring tools and since I activated them a user triggered the error and I have been able to identify the error.