Twitter-like "follow user" and "watch this" issue
What's the best way to handle many-to-many triggered relationships like Twitter's "follow this user" problem.
I have a similar problem with users "watching" streams for responses. If 10,000 users are watching a stream and someone is in charge, what's the best way to notify the watchers? All I can think of is this:
After inserting, check the "lookup table" [fields: user_id, thread_id] for any thread that matches this thread ID. This is a list of users I have to notify. For each user to be notified, insert a row into the "notification table" [fields: user_id, message, addedon, etc.]. Now I can show any user my notifications through this table.
The problem is, it all sounds very, very expensive. Especially 10,000 inserts.
There must be a better way to do this ... ideas?
source to share
In the clock table, you can add a field last_updated
and set this when the updated stream is updated. Also add a field for last_notified
, set this, when you notify the user, you will know you need to notify the user if last_updated > last_notified
. When you decide that you need to notify the user, just show them all messages from the stream with post_date >= last_updated
.
source to share