story
feed(聚合服務)
查
聯表查詢
表冗余字段java拼接user_service查詢用戶的avator和nick_namefollow_service查詢我是否關注item_service查詢我的in_box
in_box如何設計redis zset
關注
數據庫設計
MySQL
根據ER圖設計表
create table follow(`id` bigint unsigned not null auto_increment comment '主鍵',`gmt_create` datetime null default current_timestamp,`gmt_modified` null default current_timestamp on update current_timestamp,`from_user_id` bigint unsigned not null comment '',`to_user_id` bigint unsigned not null comment '',primary key(`id`)
)
根據涉及的查詢場景設置索引?
--查詢關注列表
--同一個連接同一個數據庫
select to_user_id,nick_name,avator,introduction
from follow join user on follow.to_user_id = user.id
where from_user_id=?--查詢關注列表
--同一個連接不同數據庫
select to_user_id,nick_name,avator,introduction
from a.follow join b.user on follow.to_user_id = user.id
where from_user_id=?--查詢關注列表
--表字段冗余
select to_user_id,nick_name,avator,introduction
from follow
where from_user_id=?--查詢粉絲列表
select from_user id
from follow
where to_user_id=?index idx_from_to(`from_user_id`,`to_user_id`)
item
數據庫設計
create table item(`id` bigint unsigned not null auto_increment comment '主鍵',`gmt_create` datetime null default current_timestamp,`gmt_modified` null default current_timestamp on update current_timestamp,`from_user_id` bigint unsigned not null comment '',`to_user_id` bigint unsigned not null comment '',primary key(`id`)
)
增
校驗參數
item->DB
異步任務審核nlp打標簽
異步任務(MQ)item寫入粉絲的郵箱