Jump to content

Programming friends on a social networking site


TheDudeAp

Recommended Posts

Hey guys,

 

I am programming a social networking site and I'm programming the system to have friends.  The only want I can think of to do this is under each record in the table "user" I have a column called "friends" and I populate this comma delimted and then search through all the "friends" when I need to.  I'm just worried that when people start getting 1000+ friends the system is going to crash.

 

Think there is a better way to do this? 

 

Thanks in advance,

Dan

Hi,

I would suggest that you have a sperate table that simply holds friend ids linking the two together:

 

id

user_id

friend_id

 

You simply add a new row for each friend (you might want to add a date_add "date" column so that you know how long they have been friends for)

 

This might mean you having a large table as regards number of rows but shouldn't be a problem perfomance wise and will be far easier to use.

 

Chris

Hey guys,

 

I am programming a social networking site and I'm programming the system to have friends.  The only want I can think of to do this is under each record in the table "user" I have a column called "friends" and I populate this comma delimted and then search through all the "friends" when I need to.  I'm just worried that when people start getting 1000+ friends the system is going to crash.

 

Think there is a better way to do this? 

 

Thanks in advance,

Dan

 

 

Like other people mentioned, an intermediate table between users & friends should solve your problem.

 

The anti-pattern sticky thread has a very good explanation of this along with a bunch other helpful 'did you knows'.

Hi,

I would suggest that you have a sperate table that simply holds friend ids linking the two together:

 

id

user_id

friend_id

 

You simply add a new row for each friend (you might want to add a date_add "date" column so that you know how long they have been friends for)

 

This might mean you having a large table as regards number of rows but shouldn't be a problem perfomance wise and will be far easier to use.

 

Chris

 

Just an FYI from my experience, the id wouldn't be necessary for this table. The index can be (user_id, friend_id).

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.