Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook newsfeed in mysql
    primarykey
    data
    text
    <p>I want to create a Facebook like newsfeed for my users that basically does the following</p> <ul> <li>it keeps track of the activities of users and their friends</li> <li>users can see recent friend activities on their newsfeed</li> </ul> <p>but i am not quite sure how best to implement this in mysql. Like what sort of tables will I need? What is the structure of these tables? What will I store in these tables? How will I keep track of user and friends activities. I want to build an efficient system that will scale up. I prefer working with PHP and Mysql if possible!</p> <p>I was thinking of having a NEWSFEED table and when a user does something (posts a comment, etc), I add an entry to that table for the user's friends and the user himself that will show up on their newsfeed. </p> <p>The table structure would be as follows</p> <pre><code>uid INT activity ENUM activity_id INT </code></pre> <p>So let's say I have a comments table with the following structure:</p> <pre><code>title VARCHAR(255) message TEXT </code></pre> <p>If the user posts to that table and an entry with ID=5 gets created for that user, then the following entry will be added to the NEWSFEED table</p> <p>uid=3 activity="comment" activity_id=5</p> <p>that means that to display the newsfeed for each user, I would have to do the following:</p> <p>SELECT * FROM newsfeed WHERE UID = ....</p> <pre><code>FOR EVERY ROW: CHECK activity type (if activity == 'comment') **QUERY the corresponding table and display the result (so I would query the comments table an display the person's comment)** </code></pre> <p>I am thinking of deleting entries more than >3 months old to prevent the table from getting too huge. But I don't like that I am doing independent queries to display for each activity type (just as I did above where I queried the COMMENTS table to display the comment whose ID is mentioned in the NEWSFEED table).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload