Skip to content

查询我关注的及屏蔽的节点 #11

Description

@codetalks-new

查询功能要求

查询我关注的节点
返回完整的我关注的节点。
排序注意点:

  1. 如果按时间排序的话,则按关注的时间排序。即按 UserNodeStar.created 排序。
  2. 如果按节点活跃时间排序则需要按 Node.updated 排序。
  3. 如果按活跃度排序,则需要按 Node.active_degree 来排序。

从排序需求来看,原 Node 节点需要增加 active_degree 这个字段。
对于查询语句来说,查询语句不能使用单表查询+子查询的方式。
因为排序需要用到关联表的 UserNodeStar.created 字段。
从逻辑上来说以 Node 作为主表,而以 UserNodeStar 作为右关联表。

那么下面是一个以关注时间进行排序的 SQL:

select node.* ,link.created,link.user_id
from wepost_posts_node as node 
left outer join wepost_posts_usernodestar as link on node.id = link.node_id and link.user_id == 43
where link.user_id = 43
order by  link.created

这里使用了 left outer join 是因为如果使用内联接的话,查询集将太大。
在关联条件中的 on node.id = link.node_id and link.user_id == 43 这是为了减少 关联集的大小。
因为wepost_posts_usernodestar 是记录所有人对所有节点的关注

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions