douqi1625 2013-11-03 08:46
浏览 17
已采纳

适用于存储“看到”消息的架构[已关闭]

I'm sure all of you have seen at some point at some website some message - i.e. you logged in and it stated something like "There will be a planned maintenance downtime at Tuesday 5PM PST". And then you have the tick mark for the message. When you click on it, you don't get the message shown any more.

Now, my question is how to handle this in the database. I.e. if you have 1M registered users and you decide to store this "seen" record for every user you'll end up with a 1M table which has to be read from every time someone logs in. On the other hand, if you have 10 messages like that - of course your table grows much faster. And finally, there could be messages like "Johnny,Harry,Diane and 5 of your other friends have updated their profile."

You could have like 10-50 messages like that daily. What I'm trying to think of is the best approach to this. I've implemented a lot of solutions in the past but I'm rethinking and am wondering of how others in the community are handling problems like that!

Edit: @hakre Thank you for your comment. Actually, I did describe one way I handled it in the question itself. Don't get me wrong but if I propose solutions, answers tend to discuss those proposed solutions which isn't something I'd like.

  • 写回答

1条回答 默认 最新

  • dtpa98038 2013-11-03 10:23
    关注

    Do you have any NoSQL at hands?

    I use redis, and I would create an set with all the users ids as members of the set (add the ids if the user should be marked as seen)... To check if the user has seen the message a simple SISMEMBER will suffice and it's O(1)...

    Plus, you won't need any db query or alter table for the seen field.

    http://redis.io/commands/sismember

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP