I have a dashboard for real-time updates and latest notifications.
Imagine this is a blogging system where you can subscribe to authors posts and comments.
I then want 2 type of notifications to appear in my dashboard, sorted by insertion time:
- Last posts
- Last comments
Imagine I only want 10 updates to show up when I load the dashboard (later updtes I’m getting through ajax). How should I query the database and how should I sort the results?
I’ve thought of querying the 2 tables (posts and comments) for data that I’ve subscribed, add that data to a list and sort those results for datetime and then return the last 10, but I feel this is not a very good solution since it would take lots of time to sort if those tables (and my subscriptions) begin to grow.
What are your answers/thoughts for this problem?
Query the first table ordering by descending insertion time and limiting results to 10. Then query the second table the same way. Then merge results in python and return the first 10 of them.
A django example could look like this: