I'm considering building a primative chat system (ie, just working with what I know) and I'm considering how to store the chat in the database. I was thinking of say recording the last twenty lines in twenty different id positions in the database. But then I thought each time new text is written, I would have to write all twenty positions each time? I am going to have a few second between posts coded in, but still, 20 DB calls per post?
I could put all the varchar variables in one id position - I just find that fiddley to work with? Should I just suck it up and deal with the fiddley?
Programming a chat and optimising DB calls...
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Programming a chat and optimising DB calls...
Are you using PHP or Javascript/AJAX? I ask because JS works much better for chat applications. With PHP, since you will have to re-write all of the chats each time the player wants to check for new messages (and some players may hit refresh over and over when they are expecting a new chat), it will be quite wasteful. However, with JS, you only need to get the latest chat, because you can just move the old ones up and finally out of the chat box when so many new chats push it out.
The indelible lord of tl;dr
Re: Programming a chat and optimising DB calls...
Well, good points, but I want to keep to what I know and also since I have a low population game I want to keep previous comments in chat recorded. Otherwise people will often come to an empty chat room. Atleast if there are some previous comments (with a time stamp), there's a sense of life there. Of course that makes it a bit more like a mini forum, but that works for my project!
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog