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.