Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook FQL -- very slow

$access_token = $facebook->getAccessToken();
$query = "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())";
$query = urlencode($query);
$fql_query_url = 'https://graph.facebook.com/'. 'fql?q='.$query. '&access_token=' .    $access_token;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);

This is the query. It works me faster because I have limited friends. But some app users say that it is very very slow for them if they have about 2000+ friends. They said it took 30 seconds to minutes too.

Why it is very slower? Is there any wrong in this request?

like image 966
Kamini Avatar asked Jul 16 '12 07:07

Kamini


2 Answers

Well, the first thing - as long as you filter users by uid and only select uid after that - the outer query looks redundant. So the final query can be reduced to

SELECT uid2 FROM friend WHERE uid1=me()

The second thing: it is a bit more handy to use fb php sdk to perform FQL queries, not file_get_contents, like:

$facebook->api("/fql?q={$fql}");

(taken from https://stackoverflow.com/a/7827550/251311)

like image 52
zerkms Avatar answered Oct 12 '22 11:10

zerkms


It is slower simply because there is more data to be collected. 2000+ friends is quite a lot for a single query...

Some helpful info can be found here - https://developers.facebook.com/live_status.

Other than the live status of the platform (indeed useful to know), there is also two graphs displaying the average API response time and the API error count. If you are noticing extremely slow requests, head over to that link to see if maybe it is a system wide issue.

like image 29
Lix Avatar answered Oct 12 '22 11:10

Lix