成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

mysql - 新浪微博中的關(guān)注功能是如何設(shè)計(jì)表結(jié)構(gòu)的?

瀏覽:130日期:2022-06-14 18:21:28

問(wèn)題描述

問(wèn)題解答

回答1:

個(gè)人簡(jiǎn)單猜測(cè),如有雷同,純屬巧合!有錯(cuò)誤請(qǐng)指正!

user_relation - 用戶(hù)關(guān)系表user_id - 用戶(hù)IDfollower_id - 被關(guān)注者用戶(hù)IDrelation_type - 關(guān)系類(lèi)型,1=關(guān)注 2=粉絲

業(yè)務(wù)邏輯處理

1 用戶(hù)A關(guān)注了用戶(hù)B

插入兩條記錄

insert user_relation(user_id,follower_id,relation_type) values(a_id,b_id,1);//增加一個(gè)關(guān)注的人insert user_relation(user_id,follower_id,relation_type) values(b_id,a_id,2);//增加一個(gè)粉絲

2 查用戶(hù)A關(guān)注的所有用戶(hù)

select * from user_relation where user_id=a_id and relation_type=1

3 查用戶(hù)A有多少粉絲

select * from user_relation where user_id=a_id and relation_type=2

4,5等等邏輯以此類(lèi)推。。。。

設(shè)計(jì)理由

考慮到擴(kuò)展性,數(shù)據(jù)量大了必定分庫(kù)分表,一般按user_id取模等等算法拆分,所以沒(méi)辦法用follower_id查詢(xún)出所有關(guān)注我的人(粉絲)。

當(dāng)然如果不要擴(kuò)展性或數(shù)據(jù)很小,那兩個(gè)字段正著查所有我關(guān)注的人,反著查所有的關(guān)注我的人(粉絲)

標(biāo)簽: 微博
相關(guān)文章: