Answer the question
In order to leave comments, you need to log in
Does the code only work the second time?
Why does the code work only the second time? (I mean adding myCache)
async function getUser(uid){
var response = await vk.api.users.get({user_ids: uid});
response = response[0];
var query = connection.query("SELECT * FROM `users` WHERE `id`='"+uid+"'", function(error,result){
if ( error ) throw error;
result = result[0];
if ( result === undefined ){
connection.query("INSERT INTO `users` (`id`,`name`,`balance`) VALUES ('"+uid+"','"+response.first_name+"','0');", function(error,result){
if ( error) throw error;
if ( result ) console.log('new user!');
response.balance = 0;
});
}else{
response.balance = result.balance;
}
myCache.set(`u${uid}`,response);
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question