Firestore implement Notifications View

Viewed 102

So to begin with this question is not related to Push Notifications. What I want to achieve is a View in which all notifications are displayed. Something like Instagram or Facebook.

There could be a number of resources from which these notifications could come. Lets say:

  1. Somebody likes my photo. (Came from likes table.)
  2. Somebody commented on my photo. (Came from comments table.)
  3. New Promotion. (Came from promotions table.)
  4. New Security alert. (Came from alerts table.)

What is important is that I need to display only one row per item. So if 10 people like the photo I want to update that single row in real time. Also another important thing is Pagination. This is the point where I'm having difficulties. It's very hard to implement pagination when these resources come from different tables.

So my question is: Should I create another notifications table and whenever one action is performed, I insert a new row to this table and then perform a paginated query here, or should I fetch and then merge these notifications from different tables?

1 Answers

Should I create another notifications table and whenever one action is performed, I insert a new row to this table and then perform a paginated query here?

If you are implementing this approach, it will be easy for fetching a query with pagination. I take just an example if someone is like your photo then you have all the table fields like postId, userId, and all. So you can put all the values in the 'Notification' table.

should I fetch and then merge these notifications from different tables?

This will be difficult to fetch or join different tables to show notification with pagination. It will also take time to execute queries in the database.

Related