Facebook风格的消息系统架构设计

问题描述:

我期待实现一个Facebook风格的消息系统(线程消息)到我的网站。Facebook风格的消息系统架构设计

你认为这个模式标记看起来好吗?

alt text

主义的schema.yml:

UserMessage: 
    tableName: user_message 
    actAs: [Timestampable] 
    columns: 
    id: { type: integer(10), primary: true, autoincrement: true } 
    sender_id : { type: integer(10), notnull: true } 
    sender_read: { type: boolean, default: 1 } 
    subject: { type: string(255), notnull: true } 
    message: { type: string(1000), notnull: true } 
    hash: { type: string(32), notnull: true } 
    relations: 
    UserMessageRecipient as Recipient: 
     type: many 
     local: id 
     foreign: message_id 
    UserMessageReply as Reply: 
     type: many 
     local: id 
     foreign: message_id 
UserMessageReply: 
    tableName: user_message_reply 
    columns: 
    id: { type: integer(10), primary: true, autoincrement: true } 
    user_message_id as message_id: { type: integer(10), notnull: true } 
    message: { type: string(1000), notnull: true } 
    sender_id: { type: integer(10), notnull: true } 
    relations: 
    UserMessage as Message: 
     local: message_id 
     foreign: id 
     type: one 
UserMessageRecipient: 
    tableName: user_message_recipient 
    actAs: [Timestampable] 
    columns: 
    id: { type: integer(10), primary: true, autoincrement: true } 
    user_message_id as message_id: { type: integer(10), notnull: true } 
    recipient_id: { type: integer(10), notnull: true } 
    recipient_read: { type: boolean, default: 0 } 

当我一个新的答复作出的,我会确保对“recipient_read”每个收件人的布尔值设置为false,当然还有我会确保sender_read也设置为false。

我使用的URL的哈希:http://example.com/user/messages/aadeb18f8bdaea49882ec4d2a8a3c062

(作为ID从1首发,我不希望有http://example.com/user/messages/1呀,我可以开始从一个更大的数字递增,而是。我宁愿从1开始。)

这是一个好方法吗?你的想法和建议将非常感激。

谢谢你们!

+1

UserMessage和UserMessageReply都代表一个类 - 消息。我想创建一个类并通过reply_id字段将其与自身相关联。在这里阅读关于巢关系:http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/zh#relationships:join-table-associations:self-referencing-nest-relations – Dziamid 2011-01-10 21:01:21

+0

啊,有趣。非常感谢。 – Flukey 2011-01-11 00:52:32

user_message.created_at和user_message_recipient.created_at有什么区别?

对于updated_at的同样问题。 (稍后:我想user_message_recipient.updated_at可能是收件人阅读邮件的时间,如果是这种情况,我宁愿使用更有意义的名称。)

您是否考虑过挖掘某些开源项目的源代码是否打算成为Facebook的替代品?

当我做出新的回复时,我会确保每个收件人的“recipient_read”的布尔值设置为false,当然我会确保sender_read也设置为false。

我希望这意味着dbms将验证那些布尔值设置正确。

我也尝试使用数据库创建一个消息系统,最常见的缺陷是忘记了每个用户都有不同的读取 - 未读消息的状态。我很少在数据库方案中显示,但总之,您必须考虑为每个用户为每个user_message和user_message_reply创建像isread一样的标志,这样每个用户只会看到未读消息。

这个模型呢?

MESSAGES    USER_MESSAGES 
========    ============= 
id     id 
content    message_id 
reply_message_id  recipent_id 
         read 
         trash 
         hide