This question is mainly to verify my current idea. I have a series of objects which I want to be active for a specified amount of time. For instance objects like ads which are shown in the ad space only for the amount of tim开发者_如何学Ce bought, objects in search results which should only pop up when active, and frontpage posts which should be set to inactive after a prespecified time.
My current idea is to just give those type of objects a StartDate and EndDate and filter the search routines to only show results which fall in the range StartDate < currentDate < EndDate.
Is this the normal structure or should there be some sort of auto-routine which routinely checks for objects which are "over-time" and set a property "inactive" to true or something. Seems like this approach is such a hassle since I need a checker which runs say, every 5 minutes, to scan all DB objects. Seems like a bad idea to me.
So is the first structure the most commonly used or are there any other options? When searching on google or SO the search queries only return results setting users inactive.
Unless you are dealing with a seriously large number of objects, a date filter is definitely the best method.
The only reasons to implement a check like you describe are if the filter query takes too long or you have a cache that really needs to be updated as soon as anything goes inactive. Neither of those is likely to apply for a normal web application.
精彩评论