实施“跟随"操作.使用PHP和Mysql的用户功能 [英] Implementing a "Follow" user feature using PHP and Mysql

查看:111
本文介绍了实施“跟随"操作.使用PHP和Mysql的用户功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我正在一个具有卖方和买方的电子商务平台上工作.现在,在我的情况下,卖方也可以是买方,即每个用户都可以买卖. /> 因此,我有一个名为 users 的表.现在,我想实现一个跟踪供应商/用户功能,用户可以单击关注,他会看到该列表列出的所有商品卖方(直到他取消关注).

Issue: I am working on a kind of e-commerce platform which has sellers and buyers.Now in my case a seller can also be a buyer i.e every user can buy plus sell.
So i have a single table called users.Now I want to implement a follow vendor/user feature,wherein the user can click follow and he sees all the goods listed by that vendor under his account(till he unfollows).

现在,我的传统方法是创建一个表,该表包含一个键和两列来存储关注者和随后的例如: |id | userId| vendorId
所以它会随着用户的关注而水平移动.但是,如果我有一个关注很多人的用户(例如 100 ),我的查询可能会花费很多时间来选择每个用户100条记录.

Now my traditional approach was to have a table that has a key and two columns to store the follower and the followed Eg: |id | userId| vendorId
So it will go horizontally as the users go on following others.But if I have a user following many people(say 100) my query may take a lot of time to select a 100 records for each user.

问题:如何实现跟随机制?是否有比这更好的方法?我正在使用PHP和Mysql.

Question: How can I implement the follow mechanism?Is there a better approach than this?I am using PHP and Mysql.

研究:我尝试研究了facebook和Pinterest的处理方式,但是对于我来说,这似乎有点太大了,因为我不希望立即有这么多的用户.我是否需要使用内存缓存来提高性能并避免重复查询?我可以在与Mysql并行的任何意义上使用文档数据库吗?

Reasearch: I tried going through how facebook and Pinterest handle it,but that seemed a bit too bigg for me to learn now as I don't expect as many users immedeately. Do I need to use memcache to enhance the performance and avoid recurring queries?Can I use a Document Database in any sense parallel with Mysql?

我想要一个简单但功能强大的实现,如果我的用户群逐渐增加到几千,则可以扩展.

I would like a simple yet powerful implementation that would scale if my userbase grows gradually to a few thousands.

任何帮助或见解都将非常有帮助.

Any help or insights would be very helpful.

推荐答案

由于我对这种情况的理解,用户可能会关注许多供应商,而一个供应商可能会有很多关注者,这构成了很多关系,因此在数据库模式中实现此目标的唯一规范化方法应该是使用链接表(完全如您所述).

Since, from my understanding of this scenario, a user may follow many vendors, and a vendor may have many followers, this constitutes a many<->many relationship, and thus the only normalised way to achieve this in a database schema should be through using a link table, exactly as you described.

关于性能方面的考虑,我不会对此太担心,因为可以在userId和vendorId上对其进行索引,因此查询应该很好.

As for the performance considerations, I wouldn't worry too much about it, since it could be indexed on userId and vendorId, the queries should be fine.

这篇关于实施“跟随"操作.使用PHP和Mysql的用户功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆