Reputation: 71
I find it hard to believe that Facebook uses simple sql, surely it would use some other method but lets assume for now it does use sql how would the code assimilating the 'wall' work?
Lets say that there is three tables (just for the example)
Friends: id (entry key) - uid(your id) - fid (your mates' id)
Wall:id (entry key) - username - comment - time - commentcount
comments: id (entry key) - wid (wall id (original comment)) - reply - time
Lets forget about the like part and report etc, as well as mod things (ip, ban etc.) How would this work?
Select wall.id, wall.username, wall.comment, wall.time, wall.commentcount, comments.wid, comments.reply, comments.time FROM wall inner join comments ON wall.id=comments.wid ORDER BY wall.time;
That's your own wall but how do they get friend's? A heap of unions?
Upvotes: 4
Views: 401
Reputation: 11
Well, as the founder of a social networking site, let me explain something. You're close to correct... as for your question regarding how they get friends, in a mysql situation, they would while loop through all their friends where their id matches in the friends table. Then they would while loop the comments WHERE each of the friends id matches the user's id in my case, aka $_SESSION['user_id'] = uid. Remember though, not only are the comments on a while loop, but the query is also on a while loop so that it doesn't only query one instance of the logged in user = uid.
Upvotes: 0
Reputation: 144
here you can find more information on how Facebook (and MANY other BIG sites) works.
http://highscalability.com/blog/category/facebook
Upvotes: 1