想知道Facebook如何做到“互相朋友”特征 [英] Wondering how Facebook does the "Mutual friends" feature

查看:110
本文介绍了想知道Facebook如何做到“互相朋友”特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序来允许学生管理他们的课程,而我并不知道如何设计一个特定功能的数据库。
客户希望,像Facebook一样,当学生显示目前在特定课程中的人员名单时,首先显示与登录用户最相互课程的人员。与Facebook一样的功能朋友的建议与附加的过滤器。



作为一个额外的功能,我想添加一个搜索功能,让学生搜索另一个一个,并在搜索结果中首先显示与登录用户最相互课程的人。



我目前使用MySQL,我打算使用Cassandra的其他功能,我也使用Memcached进行结果缓存和Sphinx进行搜索。



谢谢。



-



该应用程序是用Python开发的,BTW



我忘了提到标准方法MySQL查询用ORDER BY子句计算所有这些)是wayyyys太慢。因此,读取的次数比读数大得多,所以当我们添加关系人的时候,大部分逻辑都会发生一次。



我考虑更新一个特定于一个元组(用户,课程)的相互课程计数器,当登录的用户加入新课程时(或离开课程时,该课程减少)将增加所有用户的课程。

解决方案

如果您已经有了解决方案,但问题只是该查询的速度,请尽早做到。当用户的友谊发生变化时,重新运行计算这些内容的作业,并将所有结果存储起来。当您需要结果如此之快时,不要因为请求而劫持他。做这样昂贵的事情只做一次,然后再做一个请求。


I'm currently developing an application to allow students to manage their courses, and I don't really know how to design the database for a specific feature. The client wants, a lot like Facebook, that when a student displays the list of people currently in a specific course, the people with the most mutual courses with the logged in user are displayed first. Almost the same as Facebook feature "Friend suggestions" with an additional filter.

As an additional feature, I would like to add a search feature to allow students to search for another one, and displaying first in the search results the people with most mutual courses with the logged in user.

I currently use MySQL, I plan to use Cassandra for some other features, and I also use Memcached for result caching and Sphinx for the search.

Thanks.

--

The app is developed in Python, BTW

And I forgot to mention that the standard approach (using a nice MySQL query to calculate all this with an ORDER BY clause) is wayyyys too slow. So as reads are a lot more frequent than reads, I would like most of the logic to take place once, when the relation people <-> course is added.

I thought about updating a "mutual courses" counter specific to one tuple (user, course) that will be increased for all users of a course when the logged in user joins a new course (or decreased when he leaves it).

解决方案

If you already have your solution, but the problem is just the speed of that query, try doing it sooner. When a user's friendships change, rerun a job that calculates these things and store all the results away. Don't runt his as a result of a request, when you need the result so quickly. Do such expensive things only once and do them before a request is ever made.

这篇关于想知道Facebook如何做到“互相朋友”特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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