sidorares / sidorares/node-mysql2
Insert operation is not inserting data properly
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
Hi,
I am facing a problem. I have a messenger application. i am sending messages using socket.io. If i type a message slowly and emit it's working fine. But if i type several message quickly and send it to socket emit the out put is something like this
3048 : asd
3049 : asd
3056 : d
3056 : d
3056 : d
3056 : d
3056 : d
3056 : d
3056 : d
3062 : das
3062 : das
3062 : das
3062 : das
3062 : das
3062 : das
3071 : as
3071 : as
3072 : asd
3072 : asd
3072 : asd
3072 : asd
3072 : asd
3072 : asd
3072 : asd
3072 : asd
3076 : das
3076 : das
3076 : das
3076 : das
code is
await sMM.Im_message_Model.insert(senderId, receiverId, message, fileType, null, receiverType, date, time, date_time);
let fullMessage = await sMM.Im_message_Model.getRecentMessageWithUpdate(receiverId);
console.log(fullMessage.m_id+" : "+fullMessage.message);
Functions:
Im_message_Model.getRecentMessageWithUpdate = async (g_id)=>{
let query="select * from im_message where receiver=? order by m_id DESC LIMIT 1";
let [result,err]=await mysqlCon.execute(query,[g_id]);
if(result.length>0){
let prepareData=result[0];
prepareData.poster="";
if(prepareData.type!="text" && prepareData.type!="update" && prepareData.type!="document"){
prepareData.message= baseUrl+"assets/im/group_"+g_id+"/"+prepareData.message;
}
if(prepareData.type=="document"){
let fileUrl=encodeURIComponent(baseUrl + "assets/im/group_"+prepareData.receiver+"/"+prepareData.message)+"&fn="+encodeURIComponent(prepareData.fileName);
prepareData.message=baseUrl+"download?f="+fileUrl;
}
if(prepareData.type=="video"){
prepareData.poster=baseUrl+"assets/img/poster.jpg";
}
return prepareData;
}
};
Im_message_Model.insert= async (u_id,g_id,message,type,fileName,receiver_type,date,time,date_time)=>{
let query="INSERT INTO im_message (sender,receiver,message,type,fileName,receiver_type,date,time,date_time) VALUES (?,?,?,?,?,?,?,?,?)";
await mysqlCon.execute(query,[u_id,g_id,message,type,fileName,receiver_type,date,time,date_time]);
};
m_id is unique and auto increment primary key.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the reported sequence around Im_message_Model.insert and getRecentMessageWithUpdate, using mysqlCon.execute and the shown receiver query. Reproduce rapid sends and compare inserted rows with returned m_id/message values; done means the cause is isolated and the reported behavior is verified or a focused fix and test are identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, node.js
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100