What is the best way to get list of photos with me and a friend tagged in them?

Mark picture Mark · Sep 23, 2011 · Viewed 11.8k times · Source

I'm doing this fql:

SELECT object_id, pid, src_big, src_big_height, src_big_width, src, src_height, src_width 
FROM photo 
WHERE pid IN (SELECT pid FROM photo_tag WHERE subject= [me_uid]) AND pid IN (SELECT pid FROM photo_tag WHERE subject= [friend_uid] ) limit 0, 20

This works fine until I use 2 users ids who have thousands of photos with hundreds of them tagged with both uids.

In this scenario, FB returns a 500 error: "Error loading script", error code 1

I need to incrementally retrieve data as a user pages down. Getting All photos/tags for both users and then comparing the 2 full lists is not acceptable for this app.

Any thoughts?

Answer

Anatoly Lubarsky picture Anatoly Lubarsky · Sep 23, 2011

Maybe optimize it like so:

SELECT object_id
  FROM photo 
 WHERE pid IN (SELECT pid 
                 FROM photo_tag 
                WHERE subject = [me_uid] AND pid IN (SELECT pid 
                                                       FROM photo_tag 
                                                      WHERE subject [friend_uid]) LIMIT 0, 20)  

hope this helps