我想创建一个仅使用mysql的activity_feed系统。该活动将显示给进行活动的用户的关注者。活动本身将在另一个缓存表中写入(在对其他数据库进行一些询问之后,例如“帖子”)。
**ACTIVITY_FEED** <- fixed/length
-----------------
AID - INT, PRIMARY KEY, A_I <- *id of activity*
UID - INT <- *id of user*
TYPE - ENUM(post,comment,like,etc) <- *type of activity*
RID - INT <- *id relative to activity type (for example "posts" table id)*
TIMESTAMP - DATETIME
**ACTIVITY_FEED_INDEX** <- fixed/length
------------------
UID - INT <- *id of the user that request the activity feed. (the follower)*
AID - INT <- *ID of the activity that the follower will seen*
TIMESTAMP - DATETIME <- *same timestamp of activity*
PRIMARY KEY uid,aid
**ACTIVITY_FEED_CACHE**
------------------
AID - INT <- *if of activity*
CACHE_DATA - TEXT <- *json string of activity parameters* //no search needed
这个想法是插入ACTIVITY_FEED_INDEX一行,每个人都跟随进行活动的用户。 (推模式)
然后,使用如下查询:
SELECT cache.cache FROM activity_feed_index as index INNER JOIN activity_feed_cache AS cache ON cache.aid = index.aid WHERE index.uid = 'USER_ID'
用户将获得他所关注的用户的所有活动。
它可扩展吗?它正常化了吗?没关系? PS:目前我无法使用REDIS或其他NoSQL系统。所以,只有MYSQL。PS:抱歉我的英语不好:O