1

I'm implementing a design for an activity feed using the suggestion from the question: How to implement the activity stream in a social network

If I had a schema like this, how could I best query for the activity feed where activities may have corresponding tags (meaning I need to join some other tables to get tag data).

Example:

Activity 1: user4 tagged publication with tag1, tag2, tag3
Activity 2: publication rated 3 by user2
Activity 3: publication subscribed to by user9`

Activity table:

id             
user_id       (int)
activity_type (tinyint)
source_id     (int)  
parent_id     (int)
parent_type   (tinyint)
time          (datetime but a smaller type like int would be better) 

My ideas on how to implement this are:

1. Do 1 query with a LEFT JOIN then assign tags to corresponding activities with javascript.

Or

2. Store tags as JSON in a database field

1 Answer 1

2

My choice would be the LEFT JOIN option. The tags don't have to be assigned with JavaScript though. If you are using a server-side language to output the stream, you can output tags at the same time.

Option #2 is bad because it prevents you from doing (efficient) queries on tags using SQL if ever you need to in the future.

Sign up to request clarification or add additional context in comments.

4 Comments

Wouldn't it be better to let the client side handle the workload for performance? Also, I've already got the tags with relationships in my database model, I'm just trying to figure out how to avoid excessive queries for my activity feed.
For something as small as generating HTML for tags, you aren't really gaining anything by letting the client do the work.
Even if it scales to millions of reads/second? Is there any harm in doing it with javascript?
If you are having millions of reads/second, you'll have a lot more to worry about than generating a tiny bit of html for tags on the server-side. But, no, there is no harm in doing it with javascript, unless there are tons and tons of tags that could cause performance issues for visitors. The only thing you should probably avoid doing is making an AJAX request for every activity to fetch its tags.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.