Every user has a column and it will show how many people viewed his profile.
I don't need to show how many people viewed the profile only, I also want to sort views according to time.
I did it like this but if I reach 50 million and above, I'll suffer from the query because it will be slow and I may get unexpected problems.
Views table
User_Id | Viewed_Date |
---|---|
3 | ... |
2 | ... |
2 | ... |
3 | ... |
2 | ... |
2 | ... |
3 | ... |
1 | ... |
I tried to try another way and so I deleted the Views table and replaced it with the Users column
Users table
Id | Name | Views |
---|---|---|
1 | User1 | { "Last 1 day": 0, "Last 7 days": 0, "Last 30 days": 0, "Last 365 days": 0, "All time": 0 } |
2 | User2 | { "Last 1 day": 25, "Last 7 days": 0, "Last 30 days": 0, "Last 365 days": 0, "All time": 25 } |
3 | User3 | { "Last 1 day": 31, "Last 7 days": 162, "Last 30 days": 0, "Last 365 days": 0, "All time": 193 } |
The JSON looks like this
{
"Last 1 day": 0,
"Last 7 days": 0,
"Last 30 days": 0,
"Last 365 days": 0,
"All time": 0
}
I want to ask what is the best way to update views inside JSON, Any ideas, please.
(from Comment) (formerly called VIEWS
)
CREATE TABLE VISITS (
USER_ID int(11) NOT NULL,
VISITED_IN datetime NOT NULL
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci