How can i impelement a Facebook NewsFeed like feature in my PHP based community application? For example “X user uploaded a new photo, Z attending to a event”. Fetching all this data from different tables consumes too resources.
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a couple of different ways you can do this, but the one I would suggest is this. Keep a single ‘history’ table that holds all of the records for every user, a timestamp, and a description of the action along with flags (or predefined keys) for what type of action occurred. This would allow you to query a single table selectively for certain types of actions and within a set frame of time to display. However, with a lot of users this table will grow quickly so you may consider purging old data that you know you will not use again later. Pay close attention to indexes to keep the queries fast, and consider using query caching since you will probably be generating the same results frequently.
As long as you aren’t planning on using this historical data for auditing users actions then it should be fine to dump it after a while. If you do need an audit trail then you may need to consider creating a temp_history table for showing recent actions and then in a CRON move their recent actions over to a permanent audit table for long term storage.