I will try explaining the problem in as much detail as I can, without explaining the application itself.
I have a MySQL table that records time when a message was sent, and if it was read or unread.
Now I need to make a column in this table that gives message a status according to the interval of time it was unread.
For example, if message was unread for:
1h - it gets status of "1";
1day - status of "2";
2days - status of "3";
3days - status of "4";
7days and more - status of "5".
So lets say I have a message that was sent 13:20 and it is unread, it has a status of “NULL”. I need it to have a status of “1” at 14:20 and a status of “2” next day at 13:20.
Now I can think of a couple of options, but they involve Crone jobs every minute, and/or masses of calculating. My site is fast growing and I would like to find a most optimal and scalable option. Maybe there is some inside MySQL option, like triggers or something.
Any help is appreciated <3
It seems like this may be more appropriately handled in the query that retrieves the messages rather than something that updates the table continuously.
You can either compute the status in the application after retrieving the messages, or return a computed status field from the query itself: