卡桑德拉评论示例模型最佳实践

发布于 2025-01-24 02:08:16 字数 1392 浏览 4 评论 0原文

由于缺乏设计模型的认真经验,我真的希望能力的专家将我指向正确的方向。因此,有一些我找不到答案的问题。在您的允许下,我将首先举一个例子。

想象一下,我们有一些名为注释的表:

CREATE TABLE IF NOT EXISTS comments (
  disquss_id uuid, //some disqussion
  comment_id timeuuid,
  created_at timestamp,
  user_id uuid,
  comment_text text,
  PRIMARY KEY ((disquss_id), user_id, comment_id),
) WITH CLUSTERING ORDER BY (comment_id DESC);

如果我们要添加答复功能,我会看到两种方法: 使字段回复作为 MAP 类型,例如回复MAP< uuid,回复>,或做另一个表 replage> revers 这样的

 CREATE TABLE IF NOT EXISTS replies(
      parent_comment_id timeuuid, //comment_id from table `comments`
      comment_id timeuuid,
      created_at timestamp,
      user_id uuid,
      comment_text text,
      PRIMARY KEY ((parent__comment_id ), user_id, comment_id),
    ) WITH CLUSTERING ORDER BY (comment_id DESC);

第一个问题: 带有MAP字段的选项使我获得优势,可以立即获得所有答复,但可以使用Table 回复提供分页的优势。如果我们期望的话,一个评论将会有10000个答复,创建一个新表是最好的选择。我对吗?

第二个问题:如果我们决定将第二个选项与另一个表revers使用第二个选项,那么请回复评论的最佳实践?如果我们发表了100个第一份评论,我必须提出100个请求,以获取该评论的答复。这似乎不是最好的解决方案,我很困惑

第三个问题:延长第二种情况,如果我们决定为 评论,显然我必须使用计数器。我们不能在同一表中混合计数器和非计数列,这就是为什么我们必须创建另一个表“ comment_ like”的原因。在这种情况下,我们必须向数据库要求每个评论。在这种情况下该怎么办?

感谢您的建议!

I really want competent specialists to point me in the right direction, due to the lack of serious experience in designing models. So have some questions that i can't find answers to. With your permission, I will first give an example first.

Imagine, that we have some table named comments:

CREATE TABLE IF NOT EXISTS comments (
  disquss_id uuid, //some disqussion
  comment_id timeuuid,
  created_at timestamp,
  user_id uuid,
  comment_text text,
  PRIMARY KEY ((disquss_id), user_id, comment_id),
) WITH CLUSTERING ORDER BY (comment_id DESC);

If we want to add replies function, i see two ways to do it:
make field replies as map type, for example replies map<uuid, reply>, or make another table replies such

 CREATE TABLE IF NOT EXISTS replies(
      parent_comment_id timeuuid, //comment_id from table `comments`
      comment_id timeuuid,
      created_at timestamp,
      user_id uuid,
      comment_text text,
      PRIMARY KEY ((parent__comment_id ), user_id, comment_id),
    ) WITH CLUSTERING ORDER BY (comment_id DESC);

First question:
Option with map field give me advantage to get all replyes at once, but option with table replies give advantage of pagination. If we expect, that there will be 10000 replies on one comment, creating a new table is best option. Am i right?

Second question: If we decide to use second option with another table replies, what best practice to get that replies for comments? If we took 100 first comments, i must make 100 another request to get replyes for that comments. It doesn't seem like the best solution and i'm very confused

Third question: Extending the second situation, if we decide to make function for like comments, obviously me must use counters. We cannot mix counter and non counter columns in the same table, thats why we must created another table 'comments_like'. In that case we must to make request to database for every single comment. What to do in that case?

Thanks for any suggestion!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文