0

我需要建立一个消息系统,由管理员发送给成员,这是我的数据库模式

用户

id primary key
username varchar

消息

id primary key
title varchar
contents varchar

收件人

id primary key
user_id int
message_id int
status varchar'read | deleted | .....'

如果我创建一条消息并分配给所有成员,假设我有 100 万成员,则收件人一次将有 100 万个带有 message_id 和 user_id 的数据,如果管理员经常向所有成员发送消息,数据库将很快增加数据,是否有更好的结构来处理这个问题?

4

2 回答 2

1

Sending a single message to a member or couple of members should not be a problem at all, however if you want to send something to all members, then I'd suggest to add an extra layer to your messaging system to implement a notification-like messages as well.

You will lose the message status (e.g. read, unread, etc.) however I think they should not be really important in that case.

I suggest to add the logic that if there was a message assigned to for example UserID 0, then show it to all members. Of course you need to delete it at some point, so it's not disturbing the members or you can have a different styling for this kind of notification/messages as well - for example they might stuck above the inbox, etc.

P.S. It's not answering your actual question, but I thought it's worth suggesting an alternative approach also.

于 2013-11-14T08:29:54.733 回答
1

是的,而不是将 message_id 存储为 int,您可以将消息数组及其状态存储在 JSON 中。

即 message_id {001, 002, 003, 004}

您可以更进一步,将状态存储为 JSON

message_id {001:'已读', 002:'未读', 003:'已读'}

通过这种方式,您可以在 PHP/javascript 中对其进行操作,然后将其放回数据库中,这样每个用户都有一个 json 字符串来映射他们消息的最后一个已知状态。

然而,这个解决方案是不可扩展的,并且没有考虑到良好的数据规范化。但是我没有时间向你解释数据库设计——就像 Jan 说的那样,这是一个开放式问题。

这是一个广泛而简单的概述:https ://www.inkling.com/read/access-2010-missing-manual-matthew-macdonald-1st/chapter-2/six-principles-of-database

这是一个类似问题的答案:电子邮件消息系统的数据库设计

于 2013-11-14T07:56:20.070 回答