What is the best way to approach making a newsfeed?
Currently I have an observer that creates a new newsfeedactivity record everytime someone creates a record. But, to deal with privacy I end up have 7 or 8 joins to get the appropriate output.
It seems like this is going to be slow and inefficient. What's another strategy for pulling out the right newsfeedactivity records as a scope?
More details:
Currently I have a site to help users track projects that they're working on. There are public and private projects (where people can invite collaborators).
I want my newsfeed to include when public projects are created. When you are invited to a private project. When a user follows a project. And then all of the actions of the other users that you're following. Then for the private projects I have another join table to determine who has access to the projects. (There are also comments on each of these projects that I want to show up in the newsfeed as well).
All of the following relationships are currently in join tables, which is why I have a lot of joins.
To get an idea of the type of query - I'm thinking it would look something like this:
SELECT
news_feed_activities
.* FROMnews_feed_activities
LEFT JOINuser_following_relationships
ONuser_following_relationships
.following_id =news_feed_activities
.user_id LEFT JOINuser_project_relationships
ONuser_project_relationships
.project_id =news_feed_activities
.responding_to_id ANDnews_feed_activities
.responding_to_type = 'Project' WHERE (user_following_relationships
.user_id = 1 ORuser_project_relationships
.user_id = 1 ORnews_feed_activities
.user_id = 1 ORup2
.user_id = 1) GROUP BYnews_feed_activities
.id ORDER BYnews_feed_activities
.id DESC
EDIT: I think I'm probably going to end up using Redis along these lines http://blog.waxman.me/how-to-build-a-fast-news-feed-in-redis