I’m creating a public messaging service and I was wondering, in order to perform a cleanse of the oldest messages, is it okay to delete the oldest message every time a new one is submitted? Or is this approach inefficient for some reason? If so, could you specify why?
I considered create a Cron Job for this, but I’m not sure if it applies in this case.
You can schedule an event in MySQL:
DELIMITER $$ CREATE EVENT cleanup_messages ON SCHEDULE EVERY day ENABLE DO BEGIN DELETE FROM messages WHERE ......; END $$ DELIMITER ;
Answered By – Johan