Graph API 与 FQL 哪个更快?

发布于 2024-12-08 02:02:31 字数 127 浏览 0 评论 0原文

只是想知道什么时候才涉及到基本的 GET/POST。 (即获取用户个人资料等简单的事情,而不是获取每个相册中的图片等复杂的事情)

哪个更快? 图表或 FQL。

我知道 FQL 比图更新,但不确定它是否更有效。

just wondering when it comes to just the basic GET/POST.
(i.e something simple as getting the users profile and not something complicated like getting a pictures from every album)

which is faster?
Graph or FQL.

i know FQL is newer than graph, but unsure if its more efficient.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蘑菇王子 2024-12-15 02:02:31

这根本就没有可比性。虽然您可以从两者获得相同的数据(在某些情况下)
他们的意图完全不同:FQL 是一种查询语言,Graph 是一个 API。

如果使用新的 JS SDK 调用 FQL 查询本身就是图形 API 调用...

您可以(并且可能应该,如果您担心实际比较而不是理论推测)比较返回相同数据的调用速度,但您应该考虑一些事情:

  • Graph API 在数据过滤条件和数据聚合方面仍然很糟糕
  • FQL 只是无法为您提供当今应用程序所需的太多功能(例如 实时更新
  • Graph API有一个能力batch 调用,这可能会加快速度很多,这也可以用于调用 fql.query 和 fql。多查询(有点麻烦 方式)。
  • Graph API 通过字段扩展在数据过滤方面表现出色

考虑以下 FQL 文档 中的示例,子查询获取活动用户的所有用户信息,朋友:

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

这个根本不可能通过单个图形 API 调用来实现。(请参阅更新)

一旦定义了所需的数据子集,您就可以根据您的要求选择适当的检索方法。

顺便说一句,FQL 比 Graph 更古老,我们把它放在 FBML (rip) 和 FBJS (rip)

更新:

Graph API 提供批处理方式请求并指定之间的依赖关系请求中的操作。例如,通过一次调用 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"
  }
]

更新 2:
截至 2012 年 8 月 30 日,Graph API 还支持字段扩展作为附加(非常强大的)数据检索机制(包括嵌套数据)

It's in no way comparable like this. While you can get same data (in some cases) from both
their intents are completely different: FQL is a query language, Graph is an API.

Calling to FQL query if using new JS SDK is a Graph API call itself...

You can (and probably should, if you worry about real comparison and not theoretical speculation) compare speed of calls returning same data but you should take into account some things:

  • Graph API still sucks at data filtering conditions and aggregation of data
  • FQL just can't provide you too many of functionality required in today's applications (like Real-Time updates)
  • Graph API have an ability batch calls, which may speed up things a lot, this also can be used to call fql.query and fql.multiquery (in a bit cumbersome way).
  • Graph API rocks at data filtering with Field Expansion

Consider following example from FQL documentation, subquery that fetches all user information for the 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 simply not possible to achieve with a single Graph API call. (see Update)

Once you define desired subset of data to get you can choose appropriate method of retrieval based on your requirements.

BTW, FQL is much older than Graph, we had it aside to FBML (rip) and FBJS (rip)

Update:

Graph API providing way for Batch Requests and specifying dependencies between operations in the request. For example same sample as above can be achieved in a single call to 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 30 August 2012 Graph API is also support Field Expansion as additional (very powerful) mechanism of data retrieval (including nested data)

蹲墙角沉默 2024-12-15 02:02:31

我使用 PHP SDK 运行了一个简单的测试(获取封面照片 ID):

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/>';
}

结果:

图形API:1.28320002556

带有 FQL 的图形 API:0.744100093842

通过 REST API 的 FQL:0.544199943542

基本的FQL要快得多,通过graph api的FQL还可以,但是graph api太慢了......你会得到一堆无用的东西使用图形 API

I ran a simple test (getting the cover photo 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

graph api with FQL: 0.744100093842

FQL via rest api: 0.544199943542

The basic FQL is much faster, the FQL via graph api is ok, but graph api is waaay too slow... And you will get a bunch of useless stuff with the graph api

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文