L
L
LemanRass212016-09-16 14:20:28
Malware
LemanRass21, 2016-09-16 14:20:28

How to properly design MYSQL for chat on node.js?

Hello.
You need to make an adequate chat on node.js as part of an application that will have its own goodies inherent in any normal chat. On this basis, a couple of questions arose:
1) Is it advisable to store the chat history in the form [sender] [recipient] [message] [Date and time] [was read?] in MySQL BD? If the chat is very popular, won't it create too high a load on the database? And what about the number of records that will grow there with great speed? After all, they will still need to be parsed at times in order to download the history of previous messages between users?
If correspondence was only possible between 2 people, then the previous option for storing data in the database would be perfect, since by the id of the user who sent the message and by the id of the user who received it + reading from the end of the database so that it would still be sorted by time can be easily get the history of correspondence of 2 people.
2) What if you add the ability to add people to a simple chat, from which it should automatically become a group chat? What is the best way to store messages from this chat in the database now if there can be many recipients now? And how to easily get history from this dynamically created group of members?
And the last question. It seems to be easier here, but it's still not completely clear.
3)The application already has groups that the user can join. A group is just a row in the database in the groups table that has an id, a name, and other parameters. You need to implement a general group chat. I imagine it like this: in each group, the database will store an array of user IDs that are members of this group as a string. I'm concerned about the size of this line as the band grows in popularity, which makes me think I'm doing something wrong. How to do it right? In addition, if I store the list of group members in this way, I will not be able to normally perform a SELECT query for a specific user to get an array of groups in which he is a member.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
A
Andrey Sanych, 2016-08-19
@mountpoint

look in the files for something like

eval(base64_decode("DQpdfdu8Ggf9.*Q=="));

DQpdfdu8Ggf9.*Q== - это для примера, строка может быть другой

M
Mr Crabbz, 2016-08-19
@Punkie

Check the content of the posts.
And the search may not help because the redirect can be obfuscated.

D
Dmitry Aitkulov, 2016-08-19
@Scarfase1989

as an option to take a backup and compare the difference in files

S
SunHere, 2016-08-25
@SunHere

Faced this) I can help for $

D
Dmitry, 2016-09-09
@Dit81

Search for modified files and for new...

S
Sergey Zotov, 2017-08-12
@sergeyz140

Hello. Thanks for answers. The site redirected to: financenow.co/work-at-home-mom-success
It turned out that the problem was in the browser, or rather in the installed add-ons - deleted, cleaned, there is no more redirect.
Firefox browser

P
Philipp, 2016-09-16
@LemanRass21

You are misreading the chat system.
Chats have rooms, inside the rooms there are messages and participants.
Tête-à-tête is a private room with 2 participants.

room 
- id
- name
- private

participant (участник чата)
- id
- name

roster (список участников чата)
- room_id
- participant_id

history (история сообщений)
- id
- room_id
- participant_id
- timestamp
- type (тип сообщения, иногда нужны системные сообщения от ботов)
- text
- deleted

Now go ahead - learn JOINs!
Regarding the load - if the application is properly designed, the load on the database will be minimal, mainly checking who belongs to which room and writing to the history.
Any significant load will be with 10k people online. Believe me, this is a very large attendance.
With more traffic, your problem will be solved by horizontal scaling (database sharding).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question