How to stop the same data into database when the network is so slow

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to stop the same data into database when the network is so slow



I use following code to accept the regsiter call from client


regsiter


.post('/regsiter', async (ctx) => {
requestfrom = JSON.parse(JSON.stringify(ctx.request.body))
let regxemail = /^[a-z0-9]+([._\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
let email = requestfrom.email
let password = md5(requestfrom.password)
if (regxemail.test(email)) {
await userModel.checkemailexist([email])
.then(async(result) => {
if (result.length === 0) {
console.log("insert email to database")
await userModel.insertUser([email,password])
} else {
console.log("email exist")
}
})
}
})



If the visiter's network is well, this function will work well, but if the visiter's network is so slow, there's no enough response time, and it will insert some same datas into database, the result.length is always ===0, how can I stop this, any ideas?


result.length


===0





Is it possible your users are hitting Refresh when they get slow responses? That might account for mutiple requests. Also, your code sample does not show where you actually insert the the row. Please edit your question.
– O. Jones
6 mins ago





Oh, and you didn't ask about thiis but MD5 is an insecure way to hash your passwords. It's child's play to recover the passwords from MD5 hashes. If you're not sure why this is a problem, please see haveibeenpwned.com
– O. Jones
4 mins ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived