views:

1816

answers:

1

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.

Thoughts, anyone?

+3  A: 

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.

Nate

related questions