开发者

What's the best way to filter database records by Facebook friends?

We'd like to introduce a feature that lets users view game results by their Facebook friends. We currently store each user's facebook uid when they first register for our game (social sign-on). Our MySQL DB looks something like this:

User

  • user_id
  • facebook_uid

Result

  • user_id
  • score
  • resultdate

Calling the Facebook Graph API, we can produce a comma delimited list friend uid's. So one way to filter game results by facebook friends is to:

  1. run a sql IN clause on the User.facebook_uid field using the friend list, then
  2. join User.user_id to Result.user_id

We'll test t开发者_如何学编程his, but I'm concerned about the performance impact of using IN clause (friend lists can be 300+).

Does anybody have experience using a different approach?

Would enjoy any insights. Thanks.


I never use user_id in my database. Although it would be an int(5) most likely - meaning faster, Having two id's is simply confusing and you can run into issues like this.

In my experience of developing Facebook apps (about 1 year and a half now) I never had issues using an IN statement, queries were always fast. As long as you have a good database arhitecture and good PHP code, you should be fine. It's just a leaderboard afterall or similar.

You can also load that info through an AJAX call so users will never experience delays due to long SQL queries.

Another option is storing those friends for each user in a lookup table that you update everytime, but can be slightly innacurate and I think it's too much effort for the purpose of this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜