At the stage of creating a super-duper-very-best-in-the-world-messenger, a question arose. When you load the page you need to display the address book (the names of all users with whom correspondence was conducted). You can run the entire database with a script (select ... where) and output the grouped data, or you can initially store these contacts in another table and update dynamically. Which way to choose?
- It depends on what database and how indexes are configured. Take, for example, your second option. It turns out you need to check each time one user is added to another in contacts or not yet. To do REPLACE, or to hang everything on triggers. On the other hand, a contact list request does not occur as often as writing a message. And, by the way, it seems to me, you are hiding something, and for a full answer, it is desirable to get a more detailed description of the messenger itself and the principle of its work. - istem
- @istem, nothing of the kind, I just ABSOLUTELY do not know anything about the principles of these of your messengers, etc. And I deeply on them ... Just know all this is necessary. When I’m done, I’ll give you a link.)) - Deus
- @istem, right there everything is elementary - Peter sits, sees Masha, Katya and Vasya in the address book. Clicks on Vasya - both-on - all correspondence is available. The implementation is simple. The catch is in this very implementation of the address book. - Deus
- There will be time, write in a personal - I will tell you about my own implementation, it can be useful. - istem
- I did not find this your lichku. - Deus
1 answer
Brrr .... You have some strange jungle ... And what could be the problem here?
Two tables: Users and ContactList.
Table contact list, for good generally consists of the owner ID, contact ID, Status. With a unique key on the first two fields.
The owner is what you are requesting to "give me my contact list."
ID contact is a link to the user table of all those who are in the contact list.
Status ... Well, this is in order to be able to do addition permissions (that is, it is first added with status 0 - and we give little information, then, when the second party has resolved - we set status 1 and we give more information).
Naturally, for when Masha is added to Petya, two entries are inserted in this table, one for Masha, the second for Petit. And if Masha removes Petya, this does not mean that Petya Masha must also disappear))
- one@SilverIce, great. I just can’t get used to the idea that the database and saving the amount of memory used are incompatible concepts. If the user has 129 contacts, then in the table only for him there will be 129 records ... And I am constantly looking for ways with minimal costs (in my head I persistently steer the spectrum with 48 RAM). I probably do not fully understand the essence of the database. - Deus
- @Deus. Begin to wean) Industrial controllers with 500Kb RAM come across to me, and on the “controllers” based on ARM9 I even saw 1GB (actually I saw phones with gig brains). - SilverIce