未读消息通知逻辑上应该怎么做?
场景就是当平台有各种新的消息通知时,平台内的成员会有未读消息的提醒。
我本来的思路是给成员一个notice的字段,默认为空,用来记录未读消息。每当平台有新消息发布时,所有成员的notice就添加该消息的id,最终notice的结构为$id,$id,$id,。有几个,就意味着有几条未读消息,然后遍历出对应的每条消息的id,当点击浏览此信息的时候,就从notice中去除对应的$id,。
这种思路合理吗?或者更好的思路是什么?
回复讨论(解决方案)
或者我想到的另外一种思路,无论新发布了什么信息,直接将此信息以站内信的形式对于用户进行发送,好处是方便管理,坏处是站内信的量会骤然增多
表字段设置一个空值,发送消息之后这个值依然为空,当用户点击该消息的时候传递一个值, 改变该字段的状态
站内信骤然增多也没关系,没影响
新建一个消息表,每条消息对应一个用户id和notice,通过改变notice的值判断是否已读
每条信息一条记录,对应用户的id,以及是否已读
你要的这种消息系统只是一个留言板的扩展,只是增加了一个标识阅读权限的字段
为标识是否已读,可设一个表,用于存放 消息id 和对应的 用户id。此表可能会很长,可以每月一分表
不好意思刚看到
一个存储发布消息的 数组(消息id) 保存在 memcache
当用户登录的时候读取数据库的 已读消息 这个看你怎么设计了 多长时间发布前的消息失效
然后将用户在线时的数据交互保存到 memcache 这类缓存里,在线的时候 定时读 新消息通知 (因为你应该需要消息即时推送吧?)
memcache 数据多长时间设置为失效 当数据失效的时候 用户需要 重新读取数据库内的数据重新生成memcache中的临时缓存数据
差不多就这样吧 看看你有多少用户 要吃多少内存 多结合几种方法因为用户多 请求可能会很多 尽量减少读写数据库.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...
