【问题标题】:Facebook style messaging system schema designFacebook 风格的消息系统架构设计
【发布时间】:2011-01-10 16:02:19
【问题描述】:

我希望在我的网站中实现一个 facebook 风格的消息传递系统(线程消息)。

你认为这个架构标记看起来不错吗?

学说 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 开始。)

这是一个好方法吗?您的想法和建议将不胜感激。

谢谢大家!

【问题讨论】:

  • UserMessage 和 UserMessageReply 都代表一个类 - 消息。我会创建一个类并通过reply_id 字段将其与自身相关联。在此处阅读有关嵌套关系的信息:doctrine-project.org/projects/orm/1.2/docs/manual/…
  • 啊,有趣。非常感谢。
  • 你用这个了吗?它是在 Rails 3 中完成的吗?

标签: mysql database-design symfony1 doctrine


【解决方案1】:

这个模型怎么样?

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

【讨论】:

    【解决方案2】:

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

    updated_at 的问题相同。 (后来:我猜 user_message_recipient.updated_at 可能是收件人阅读邮件的时间。如果是这样,我更喜欢一个更有意义的名字。)

    您是否考虑过挖掘一些旨在替代 Facebook 的开源项目的源代码?

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

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

    【讨论】:

    • 你好麦克,谢谢你的回复。 created_at,updated_at。这是 ORM 的插件行为。每条记录都有一个 created_at 字段。并且当一条记录被更新时,它的 updated_at 字段也会相应地更新。我喜欢有这种行为。哦,是的,dbms 会验证它,但你有更好的主意吗?我可以有上面评论中建议的线程表,并且有 parent_id、child_id。谢谢。
    • 我在考虑那些在数据库中声明为“NOT NULL”和“DEFAULT FALSE”的布尔值。这保证了他们会从正确的价值观开始。
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多