有什么方法可以加快/优化facebook多重查询?

时间:2014-02-27 21:56:12

标签: facebook facebook-graph-api facebook-fql facebook-php-sdk

我正在运行一系列查询以查找朋友的近期位置信息,获取用户个人资料数据和地址信息。我能够做到这一点的唯一方法是使用4个查询,这些查询似乎以800ms范围为基准,而不是非常快。查询看起来像这样

 {
  "posts": "select id,app_id,author_uid,post_id,message,post_id,tagged_uids,page_id,timestamp from location_post where author_uid in (select uid2 from #friends) and timestamp < 1393537146 order by timestamp desc limit 3",
  "placenames": "select name from page where page_id in (select page_id from #posts)",
  "friends": "select uid2 from friend where uid1 = me()",
  "usernames": "select name,uid,pic from user where uid in (select author_uid from #posts)"
}

我认为它真正挂起的地方是第一个查询是“朋友一个”,所以它会查询所有朋友,然后用它来查找最近的帖子。

任何优化建议或其他策略将不胜感激。

1 个答案:

答案 0 :(得分:0)

你至少可以在帖子查询中包装好友查询,因为它只在那里被引用,如下所示:

{
  "posts": "select id,app_id,author_uid,post_id,message,post_id,tagged_uids,page_id,timestamp from location_post where author_uid in (select uid2 from friend where uid1 = me()) and timestamp < 1393537146 order by timestamp desc limit 3",
  "placenames": "select name from page where page_id in (select page_id from #posts)",
  "usernames": "select name,uid,pic from user where uid in (select author_uid from #posts)"
}