朋友圈状态可见性探讨
qq空间里的状态是全可见的,而微信朋友圈的状态只有好友可见。同时别人的状态下面,也仅能看到自己的朋友的评论和点赞。这是如何做到的呢?本文从Mysql数据表的设计来探讨一种实现方法。
现在有这么一张好友关系图:
图中连线代表了两人互为好友(状态相互可见),当然像不让某好友看自己状态,不看某好友的状态这些功能也容易实现,实现方法后面会提到。这里以常规的状态相互可见作为主要探讨内容。
例如:高育良发表一条新状态,而高小琴、祁同伟、李达康都点了赞。在高书记的视角下应该是这样的:
表的设计
在这里共设计4张表。分别为状态表(tb_newmessage),用户表(tb_user),好友表(tb_friends)和点赞表(tb_like)。我们没有考虑评论的可见性,因为实现起来和点赞基本相同。
状态表的创建:
create table if not exists tb_newmessage(
message varchar(50) not null,
mid int not null,
uid int not null
)engine=InnoDB default charset=utf8;
用户表的创建:
create table if not exists tb_user(
uid int not null,
uname varchar(50) not null
)engine=InnoDB default charset=utf8;
好友表的创建:
create table if not exists tb_friends(
firstuid int not null,
seconduid int