I want to check an item in my database every x
minutes for y
minutes after its creation.
I've come up with two ways to do this and I'm not sure which will result in better efficiency/speed.
The first is to store a Date field in the model and do something like
Model.find({time_created > current_time - y})
inside of a cron job every x
minutes.
The second is the keep a times_to_check
field that keeps track of how many more times, based on x
and y
, the object should be checked.
Model.find({times_to_check> 0})
My thought on why these two might be comparable is because the first comparison of Dates
would take longer, but the second one requires a write to the database after the object had been checked.