'How to achieve optimal read/unread message count for spring based application
I am working on the some Java based web application. where we need to maintain unread count for specific set of user( which is grouped by some resource say Documents) when someone else posting a comment in an application. For maintaining a comment we are using MySQL. Let me explain the DB schema:
TABLE 1: Document which contain following attributes
ID, DOCUMENT_NAME, SOME OTHER Parameters
TABLE 2: Comment which contain following attributes
COMMENT_ID, MESSAGE, DOCUMENT_ID(foreign key with table 1)
Note: one-to-many relationships in table 1 & table 2.
Now, Suppose 3 user(Let say A,B and C) belong to document 1. let say User A post a comment for document 1, at that moment we will update table 3(below one) to track list of unread commentIds for User B & User C. Once user view there message we will again the commentIds for particular. Similar if user delete comment again we will update table 3.
Table 3: Document-comment-unread
DOCUMENT_ID, USER_ID, UNREAD_COMMENT_IDS(List of unread commentIds)
Whenever user posting a comment for document we will UNREAD_COMMENT_IDS list asynchronously in table 3 using some AWS Lambda. Similarly, If user want to delete some unwanted comment that time we will remove from all user rows in table 3 who belong to particular documents and whenever any user who seen all comments to same documents in that case we need to reset Unread_comment_ids again to empty for specific documents. This whole approach takes lot of DB operation whenever posting/deleting/viewing a comments. That is quite cumbersome.
What we are thinking to re-architect the implementation approach. Is it there any other efficient way to achieve similar kind of functionality?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
