siteshen
2014-03-31 09:45:19 +08:00
1. 用一张表,notification(from_user_id, to_user_id, type, object_type, object_id, sent_at, read_at, params),其中type标识类别(follow, comment, reply etc.),object_type和object_id唯一标识了和这条消息相关联的对象,params-JSON字段暂保留吧,指不定某些奇葩的通知模板中要用这个;
2. 删除文章(article_id)之后,执行:
delete * from notification where content_type = 'article' and object_id = {article_id};
3. 至于消息数,select count(*) form notification where read_at is null(折叠我吧)。