0

I have a table Friendships with this fields:

|ID|Friend_owner_ID|freind_ID|

imagine that one of members of website sends a comment and I want inform all of his friends. so I would select all of friends of the member:

Select friend_id from Friendships where friend_owner_id=$comment_sender_id

and for each row I should:

insert into Notifications set reciever_ID=$friend_id, content='$content' 

table of notifications would be like:

|id| reciever_ID| content |date|

and at last I must:

select content from notifications where reciever_id=$other_member 

So if someone that has 5000 friends send a comment I should insert 5000 rows to the table wich does not seem to be wise and will consume so many resources.

Is there a better way?

M4N
  • 94,805
  • 45
  • 217
  • 260
Mehdi Azizi
  • 187
  • 2
  • 10
  • You might want to look [this question](http://stackoverflow.com/questions/1443960/how-to-implement-the-activity-stream-in-a-social-network). Seems like there are some nice answers. – Meeuuuhhhh Jul 18 '14 at 07:07
  • With a small notification record (only a few bytes) I wouldn't worry about it. Especially if you delete notifications once they have been processed the storage requirements will be small. The only concern is what 'content' contains? If that is a large field with the contents shared between all the friends then storage could get excessive. Each to normalise that out though. – Kickstart Jul 18 '14 at 09:31

0 Answers0