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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'.

Link to comment
Share on other sites

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).

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.