API vs FQL chart which is faster?

just wondering when it comes to basic GET / POST. (something simple, like getting a user profile, not something complicated, like getting images from each album)

which is faster? Graph or FQL.

I know that FQL is newer than graphics, but not sure if it is more efficient.

+6
source share
2 answers

This is in no way comparable. Although you can get the same data (in some cases) from both their intentions are completely different: FQL is a query language, Graph is an API.

A call to an FQL query if using the new JS SDK is a call to the Graph API ...

You can (and probably should, if you're worried about a real comparison, not theoretical speculation), compare the speed of calls returning the same data, but you have to consider some things:

  • The charting API still sucks data filtering conditions and data aggregation
  • FQL simply cannot provide you with too many functions needed in modern applications (for example, real-time updates )
  • The graphics API has batch capability, which can speed up a lot, it can also be used to call fql.query and fql.multiquery (in a bit cumbersome way).
  • API graphs when filtering data with Field Expansion

Consider the following example from the FQL documentation , a subquery that retrieves all user information for an active user and friends:

 SELECT uid, name, pic_square FROM user WHERE uid = me() OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) 

This is simply not possible with a single call to the Graph API. (see Update)

Once you determine the desired subset of data, you can choose the appropriate extraction method based on your requirements.

BTW, FQL is much older than the chart, we left it in the direction of FBML (rip) and FBJS (rip)

Update:

Graph API that provides the Batch Query path and indicates the dependencies between operations in the query. For example, the same example as above can be achieved with a single call to the Graph API

 POST https://graph.facebook.com/ POST Data: batch=[ { "method": "GET", "name" : "get-friends", "relative_url": "me/friends?fields=id", }, { "method": "GET", "relative_url": "?ids={result=get-friends:$.data.*.id}&fields=id,name,picture" } ] 

Update 2:
As of August 30, 2012, the Graph API also supports Field Extension as an additional (very powerful) data retrieval mechanism (including embedded data)

+17
source

I did a simple test (getting the cover id) using the PHP SDK:

 public $microtime_start = 0; public function getExecutionTime() { return round(microtime(true) - $this->microtime_start, 4); } public function getFQL($request, $filter = true, $multiFilter = true) { if(is_array($request)) { $query = '{'; foreach ($request as $key => $q) { $query .= '"'.urlencode($key).'":"'.urlencode(addslashes($q)).'",'; } $query = substr($query, 0, -1).'}'; $data = $this->callAPI('/fql?q=' . $query); if($filter) { $data = $data['data']; if($multiFilter) { $data = $data[count($data)-1]['fql_result_set']; } return $data; } } else { $data = $this->callAPI('/fql?q=' . urlencode($request)); if($filter) { return $data['data']; } } } public function callAPI($path) { $params = array('access_token' => $this->getAccessToken()); return $this->api($path, 'GET', $params); } public function getCoverPhotoId($uid) { $time = $this->getExecutionTime(); $albums = $this->api("/me/albums"); $album_id = ""; foreach ($albums["data"] as $item) { if ($item["name"] == "Cover Photos") { $album_id = $item["id"]; $profile_picture_id = $item["cover_photo"]; break; } } $time2 = $this->getExecutionTime(); echo 'graph api: '.($time2 - $time).'<br/>'; $data = $this->getFQL(array( 'query1' => 'SELECT cover_object_id FROM album WHERE owner = ' . $uid.' AND name = "Cover Photos"' )); $time3 = $this->getExecutionTime(); echo 'graph api with FQL: '.($time3 - $time2).'<br/>'; $data = $this->api( array( 'method' => 'fql.query', 'query' => 'SELECT cover_object_id FROM album WHERE owner = ' . $uid.' AND name = "Cover Photos"' ) ); $time4 = $this->getExecutionTime(); echo 'FQL via rest api: '.($time4 - $time3).'<br/>'; } 

Results:

graph api: 1.28320002556

API chart with FQL: 0.744100093842

FQL via rest api: 0.544199943542

Basic FQL is much faster, FQL through the api graph is ok, but the waaay api graph is too slow ... And you get a bunch of useless things with the api graph

+3
source

Source: https://habr.com/ru/post/898555/


All Articles