views:

355

answers:

1

Hi,

I'm trying to get my head around whether it would be possible to do something with an FQL multi-query rather than multiple API calls.

Here is my code:

var queries : Object = {

"user_list":"SELECT uid2 FROM friend WHERE uid1 = "+uid

,"event_id":"SELECT eid, start_time, end_time, location, pic, name FROM event 
WHERE eid IN (SELECT eid FROM event_member 
WHERE uid IN (SELECT uid2 FROM #user_list) 
AND rsvp_status='attending') AND start_time > " + nowSecs + " 
AND start_time < " + (nowSecs + 2500000) + " ORDER BY start_time ASC LIMIT 20"

"user_name":"SELECT name FROM user 
WHERE uid IN (SELECT uid FROM event_member 
WHERE eid IN (SELECT eid FROM #event_id) 
AND uid IN (SELECT uid2 FROM #user_list) AND rsvp_status='attending')"
 };

At the moment there are too many results being fetched in my 'event_id' query, I currently get the full list of events for each person stored in the 'user_list' query, which I would ideally like to only get 1 event for each person, and then sort those results. I can't seem to do this, using LIMIT I only get 1 result back in total, but not for each person.

Additionally, and more importantly, I only want one result per event in the 'user_name' query, at the moment I sometimes get multiple members who are attending the same event, and this causes problems as I have no way of matching the user names up with their corresponding event once the results are received. I have also noticed that if the same user is going to two different events contained in 'event_id' there is only one instance of their name in the result, which is also undesirable.

At the moment I am making 20 API calls once I have the 'event_id' results and then sorting the data returned, which is really slowing down my app.

Can anyone suggest how I could achieve what I want, and thus optimise the queries please?

Sorry for the long post, but this has been getting on my tits for days!

Thanks

A: 

From what I can tell in reading through, you want to get:

  1. A list of all of your friends,
  2. The most recent event that each friend has said they'd attend.

This is very similar to the problem presented here, with the exception that he's going after 2 results for each item and you're searching for only one.

David T. Macknet