4

I'm new to web development and am managing to complete a site in pyramid but I want to have some kind of messages service and not sure where to start.

I want something like Quora or stackoverflow where alerts from the sites are send to the user(and maybe they can message each other). What do I need to do this? Is there a library or tutorial that can help me understand all thats involved or do I simply create a data model for messages and query the database for this? I want a way to allow users to track activity of other users and communicate with each other and I do not want to recreate email.

Is there a proper easy way to do this that could work with pyramid?

Update: I found a few resources and I think I get a idea. It would be great to learn if there's a more generally accepted way of doing it but I'm thinking I can just create this structure and query it for new messages every x seconds:

CREATE TABLE `messages` (
`message_id` int(11) NOT NULL auto_increment,
`from_user` varchar(65) character set latin1 collate latin1_general_ci NOT NULL,
`to_user` varchar(65) character set latin1 collate latin1_general_ci NOT NULL,
`message_title` varchar(65) NOT NULL,
`message_contents` longtext NOT NULL,
`message_read` int(11) NOT NULL default '0',
PRIMARY KEY (`message_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=21;
tshepang
  • 12,111
  • 21
  • 91
  • 136
Lostsoul
  • 25,013
  • 48
  • 144
  • 239
  • By "messages" and "alerts" - do you mean those real-time notifications which appear on SO even without user refreshing the page? E.q. "1 new answer to this question, click here to load answers"? Or are you not interested in this aspect and just want something more static, similar to, say, "personal messages" feature of phpbb forums? – Sergey Jul 15 '12 at 21:15
  • @Sergey I'm more interested in learning how to create the backend message system. I thought the difference of what your describing can be achieved by client side javascript to keep checking or push to the browser? Ideally I want it to be real time though. – Lostsoul Jul 15 '12 at 21:44

1 Answers1

2

You get the basic idea : you just need a table to store the messages. A single table is enough as long as you don't handle broadcast messages.

A few comments about the structure you proposed :

  • If you don't know about it yet, you should take a look at sqlalchemy. It's a great tool to handle a database and it's commonly used with pyramid.
  • You should use the keys from the user table for from_user and to_user instead of storing the name in order to avoid wasting space.
  • If your application is supposed to handle more than a few requests, you should consider indexing on some columns, depending on the queries you do. If you often query for all the message from some user, index on from_user. If you query for all unread message from some user, use a composite index on from_user and message_read (how to do it in sqlalchemy). That should greatly speed up your requests.
Community
  • 1
  • 1
madjar
  • 12,691
  • 2
  • 44
  • 52