数据库定期清理
我正在创建一个公共消息服务,我想知道,为了清理最旧的消息,是否可以在每次提交新消息时删除最旧的消息?或者这种方法由于某种原因效率低下?如果是这样,您能具体说明原因吗?
我考虑为此创建一个Cron Job,但我不确定它是否适用于这种情况。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 MySQL 中安排事件:
http://dev.mysql .com/doc/refman/5.1/en/create-event.html
You can schedule an event in MySQL:
http://dev.mysql.com/doc/refman/5.1/en/create-event.html
我建议 Cron Job,我相信每条消息都有时间戳,因此您可以借助 cron 运行上的时间戳删除旧帖子。
I suggest Cron Job, I believe there is time stamp with each message so you can remove older post with help of time stamp on cron run.
这听起来不太合适。删除旧消息的适当性不太可能取决于新消息 - 例如,如果您打算将消息保留至少一个月,那么如果您突然收到一条消息,您就不想开始删除最近的消息短时间内收到大量消息。
我建议您制定出“垃圾”标准,然后安排一项常规工作来批量删除旧消息(例如每天一次)。
That sounds unlikely to be appropriate. The appropriateness of removing an old message is unlikely to be dependent on the new message - for example, if you're meant to keep messages for at least a month, then you don't want to start deleting recent messages if you suddenly get a lot of messages in a short period.
I suggest you work out your "garbage" criteria and then schedule a regular job to batch delete old messages (e.g. once a day).