开发者

How can I run sort of "for" statement via FQL MuliQuery

Basically,

I've got a function that runs through a user's entire friend list, then pick's up each friend's last status post. Now, for someone that has 1500+ friends or even 300+ the time to exec adds up quickly. I.e. running 100 friends through takes approx. 65 seconds.

So I figured, this would run better as a batch through MultiQuery. Here's the basic concept:

$mq = array(
    "query1"=>"SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 5",
    "query2"=>"SELECT actor_id, message, created_time, permalink FROM stream WHERE source_id IN (SELECT uid2 FROM #query1) AND actor_id IN (SELECT uid2 FROM #query1)"
);

So this actually works great, however query2 output's all the user's news feed; If I set it to "LIMIT 1" then that set's up the entire query2 to be limited to 1 开发者_如何学编程output instead of 1 output per user.

Any ideas or recommendations is greatly appreciated.


If you need just the current status, you can just fetch "status" field of the user table. i.e.
SELECT uid, status FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())

however this is a bit different if you need strictly the latest status of all friends of the user. But it will be much faster.

hope this helps

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜