whn
whn

Reputation: 391

Methods for getting the count of unread messages

Here's the deal: There's a one huge database of topics(containing a number of messages) and one huge database for users. Each topic may be linked to many users(obviously each user is link to many topics). There is a field in the database(linking users with topics) that keep a number of unread messages. So I'm trying to find a fastest way to get this number for every topic linked with a current user. It's important that this number changes pretty fast therefore the method of reading this field everytime from database will slow down everything. Is there any topics in the web(I search for a good 50 minutes and still with nothing) or maybe just Your advices about making it faster(I was thinking of making the separate table but it turned out to be slow too). Thank you!

Upvotes: 1

Views: 1171

Answers (1)

Aram
Aram

Reputation: 716

Caching! You have to store in user record unread messages and topics. As soon as user will get new messages or topic attached to him you have to update these fileds and same when he will read them. You can store this data in other kind caches (faster ones). This is called de-normalisation.

Also you have to setup proper table indexes on these tables.

Upvotes: 1

Related Questions