Talk:Fql.multiquery

From Facebook Developer Wiki

Jump to: navigation, search

Fql.multiquery sounds perfect for my needs...as long as it is available via the javascript api. Is it? (Fql.multiquery is not listed at http://wiki.developers.facebook.com/index.php/API as of 20-Jun-09.)

It is, via FB.ApiClient.callMethod. We might add it to the JS client library as a new method, too, but for now, use callMethod. Pete (563683308 11:40, 22 June 2009 (PDT))

Thanks very much for the tip. The documentation is incorrect regarding the calling method. It is stated in the wiki docs [1] as "FB.ApiClient.callMethod". However, for the javascript api, the correct format is "FB.apiClient.callMethod". This should be corrected or the js api call added.

[edit] How do you know each attendee's RSVP status?

In the given example, you get uid and rsvp status from an event, and then you get name, url, and pic of all people who are members of the event.

But you don't know what each person's RSVP status (rsvp_status) is, right?

The first query gets you each invitee's UID and that invitee's RSVP status. I'm not sure I understand what you're asking here. Pete -- 563683308 14:48, 5 October 2009 (PDT)

Is there any way to get that info and still use just one call to fql.multiquery?

[edit] ==

For example, say you want to get some data about a user attending an event. Normally, you’d have to perform two queries in a row, waiting for the results of the first query before running the second query, since the second query depends on data from the first one. But with fql.multiquery, you can run them at the same time, and get all the results you need, giving you better performance than running a series of fql.query calls. First, you need to get the user ID and RSVP status of each attendee, so you’d formulate the first query – query1 – like this: "query1":"SELECT uid, rsvp_status FROM event_member WHERE eid=12345678"

Then to get each attendee’s profile data (name, URL, and picture in this instance), you’d make a second query – query2 – which references the results from query1. You formulate query2 like this: "query2":"SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #query1)"

[edit] Suggestion: flag to indicate query result should not be returned

Sometimes (probably often), multiquery is used to create a temporary set of results and then use those temporary results to create the actual desired resultset. When this is done, the caller has no interest in retrieving the temporary resultsets. E.g., slightly paraphrasing the example already in the article:

{

   "query1" : "SELECT uid FROM event_member WHERE eid=12345678",
   "query2" : "SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #query1)"

}

In this case, we probably have no interest in receiving the first resultset back to the caller; we only want to use it to create the second, which is the one we actually want. If we could flag the query1 as "do not return this resultset to the caller", we could reduce unecessary bandwidth. Perhaps prefixing the query name with a '-'? E.g.

{

   "-query1" : "SELECT uid FROM event_member WHERE eid=12345678",
   "query2" : "SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #query1)"

}

As the caller would explicitly specify the '-', this should be a non-breaking change. If there are good reasons to keep the number of resultsets the same as the number of queries, the '-' could then be used to cause returning an empty resultset in that position instead.

reference