Facebook — best way to do FQL “join” with event and event_member?

北城余情 提交于 2020-01-11 23:02:30

问题


In a Facebook app I need to get a user's events for a date range and his rsvp status for each event.

I can get the user's events fine, but at the moment I'm looking up the rsvp status for each event one at a time, and the app is timing out for people with a large number of events.

I'm getting the user's events this way:

$fql = "SELECT eid, name, start_time, end_time 
        FROM event 
        WHERE eid IN (SELECT eid 
                      FROM event_member 
                      WHERE uid = $user) 
          AND start_time > '$timestamp' 
        ORDER BY start_time";

This part is working fine.

And here's how I'm getting the rsvp status for each event, one at a time:

$fql = "SELECT rsvp_status 
        FROM event_member 
        WHERE uid = $user
          AND eid = '$event_id'";

This also works fine on an event-by-event basis, but the app page times out when the user has many events since each event is having to get looked up each time.

With normal SQL, I could easily do this with a join, but joins aren't allowed in FQL.

One possible solution is to do them in batches by looping through each rsvp_status possibility, like this:

$fql = "SELECT eid, name, start_time, end_time 
        FROM event 
        WHERE eid IN (SELECT eid 
           FROM event_member 
           WHERE uid = $user 
           and rsvp_status = 'attending') 
        AND start_time > '$timestamp' 
        ORDER BY start_time";

This would reduce the number of FQL calls down to the number of rsvp_possibilities (three I think), but ideally I'd rather do it in one FQL call.


回答1:


There's not a way to do a join however you can use FQL.Multiquery to batch your 4 queries into a single call. The 4 queries would be 1 each for the 4 possible event responses: attending, unsure, declined, and not_replied.



来源:https://stackoverflow.com/questions/1045842/facebook-best-way-to-do-fql-join-with-event-and-event-member

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!