Reputation: 429
So, I have a mysql db, and lets say we have donation
table, and I have a Java application.
My donation table have columns such as: user_id
, tier
, start_date
, and end_date
. Both start_date
and end_date
is bigInteger and have miliseconds time format.
I already coded and worked the insertion method in Java, so I can insert the start_date, and the end_date (end_date=start_date+30 days) and other columns data to the table.
What I don't understand is what is the best way to check and lets say, a method to demote the user back to the default tier when the server time is equals with end_date from the db.
Should I check every minutes/hours if servertime > end_date? (I think this way is somewhat redundant and performance hungry to the system) Or are there a better way to do it?
Thank you very much!
Upvotes: 0
Views: 41
Reputation: 10151
You could load a chunk (the next n) endDates (ordered) from DB and keep them in RAM. here you can keep them ordered and trigger an event (polling or a sleeping thread) when the top element passes the servertime. When all your endDates in RAM are over, read the next chunk from DB.
This way you keep the frequency of db queries low and also the RAM usage (by selecting an n suited for your application).
Upvotes: 1