【问题标题】:Design Reddit Comment API using SQL使用 SQL 设计 Reddit 评论 API
【发布时间】:2022-08-22 05:12:26
【问题描述】:

我们正在为支持其应用的 Reddit 新后端构建评论模型。 我们提出了以下评论结构。右侧的数字是每条评论的点赞数。

- Comment uuid 1: (Root level comment)                   89
|-- Reply uuid 2 (First level reply comment).            150
    |-- Reply uuid 7 (Second level reply comment)        92
         |-- Reply uuid 8 (Third level reply comment)    40
|-- Reply uuid 3 (First reply comment)                   112
|-- Reply uuid 4 (First reply comment).                  1
    |-- Reply uuid 9 (Second level reply comment).       0
         |-- Reply uuid 10 (Third level reply comment).  3
|-- Reply uuid 5 (First reply comment)                   5
|-- Reply uuid 6 (First reply comment)                   10
    |-- Reply uuid 11 (Second level reply comment).      78
         |-- Reply uuid 12 (Third level reply comment)   200

目标:编写一个 API 以获取给定根级别评论的按 Like 计数排序的前 5 个 cmets。 如果评论是二级或三级回复评论,则获取整个线程。 API 一次不应返回超过 5 个 cmets。

例如:API 的第一次调用 -> 返回 cmets 2、3、6、11 和 12。 第二次调用 API -> 返回 cmets 7,8 & 5。

  1. 如何在 SQL 中存储数据?假设评论具有 ID、评论消息、点赞数、时间戳和父评论 ID。
  2. API 是什么样的?应该有一个海量的 SQL 查询吗?
  • 如果 ”[你] 正在为 Reddit 的支持他们的应用程序的新后端构建评论模型”,Reddit现有的SQL结构和API不会回答你的两个问题吗……????当 Reddit 可能已经有标准可以代表您做出这些决定时,为什么 Stack Overflow 能够对此发表意见?
  • \"...支持他们的应用程序。\" 看起来像一个家庭作业问题。
  • 是的,这是一个家庭作业问题。关于如何解决这个问题的任何想法?

标签: python sql api depth-first-search breadth-first-search


【解决方案1】:

在这种情况下预期的输出是什么:

- Comment uuid 1: (Root level comment)                                1
|-- Reply uuid 2 (First level reply comment).                         10
    |-- Reply uuid 3 (Second level reply comment)                     100
        |-- Reply uuid 4 (Third level reply comment)                  123
            |-- Reply uuid 5 (Fourth level reply comment)             321
                |-- Reply uuid 6 (Fifth level reply comment)          456

?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-02
    • 2020-05-23
    • 1970-01-01
    • 2014-03-06
    • 2020-02-10
    • 1970-01-01
    • 2010-09-13
    • 1970-01-01
    相关资源
    最近更新 更多