Reputation: 3313
I'm starting to develop an activity stream. I've read both How to implement the activity stream in a social network and What’s the best manner of implementing a social activity stream?. What I haven't found is the best way to add comments to the activities. As in facebook, each comment can be commented by another person.
If each activity comment is saved as another activity, then I would not be able to get the activity of that comment without doing a query. So the solution I'm thinking is to save the comments inside the serialize data field of each activity. If the user wants to delete his comment, I would have to update that activity.
Is this the correct solution? Is there a better approach?
Thanks!
Upvotes: 2
Views: 2757
Reputation: 3455
I agree with Jakub - it depends on your backend, but what you're after is an efficient method for storing a tree. If you're using an SQL database, I'd store both the parent activity, and the root of the tree (master id?). That way you'll be able to grab an entire tree of comments quickly, given any comment or activity id.
Your lookup code would then go something like:
An example, if that helps:
I remember reading an example of this using a document based store with Couch-DB. I can't find it now, but from memory it used something similar (master ids for parent records).
Upvotes: 1
Reputation: 40543
This kind of depends on what type of backend are you using and what are your constraints.
Serializing the comments seems a reasonable approach or I guess you could just simply use a polymorphic comments table (if you're using a relational db).
Upvotes: 0