Home > other >  what is the best way to implement posts that expire after a period of time?
what is the best way to implement posts that expire after a period of time?

Time:04-06

I am working on a react native & MongoDB project that has posts which expire after 7 days from the time of creation. and then change the status to expired.

enter image description here

I am currently thinking of checking at the start of each day for posts that will expire soon then notify the user, but how would I actually change the status to expired at the exact moment it expires?

CodePudding user response:

Since your posts have the creationTime as attribute I would get the current time every one minute or so and then check if the creationTime 7 days is smaller than the current time and if so, remove the post. If you really need it at the EXACT time, you can get performance problems with a lot of posts as you would have to implement potentially multiple timers and they are really heavy.

  • Related