I’m working on an app (Rails 3.2, Mongoid) that takes all (by all I mean ‘a lot’) photos from a user. First, we get the albums (<userid>/albums), then, for each album, we take the photos in it (<albumid>/photos), then, the user photos (<userid>/photos). Then we do some operations on each photo, and save them to a DB.
Right now, as a safety net, for each ‘orphan’ photo, I check if the photo is not already present, to avoid duplicates. The current check is done on the db with a exists query. However, is makes lots of db queries, and this is not acceptable. I tried to do it server side, using an array to keep track of the photos, but it was way slower (I used Array#select if my memory is correct).
So, two questions : 1/ Is this ‘safety net’ useful, or can I take for granted that the orphan photos cannot be duplicates ? I’m thinking yes, but I think the check is done for a reason.
2/ If I have to check in order to be sure that there is no duplicates in the database, how should I do it in order to be efficient ?
EDIT
Ok looks like there truly can be duplicates, so question 1/ is solved. Now about 2: is it possible to “guess” from the retrieved photo fields if it belongs to an album, even though there’s no field like album_id ? As in “if the photo is not from user and user is tagged in” -> orphan ?
Thanks for you time!
Yes you can 🙂
From the documentation: Photo FQL table
For a given photo with id XXXXXX:
If you don’t get anything, that means you queried a photo which is out of your
access tokenreach (query a photo of someone else).You need
user_photospermission to access the user photo orfriends_photosto access one of the user friends photo.Otherwise, you should have the album id of that photo in
album_object_idMake sure in the Graph API explorer to click the Get Access Token button and check the
user_photospermission when you test the query.P.S.
I have tested this on various photos just to be sure and all tests came back
positive🙂Link to test in Graph API explorer:
(don’t forget to change the XXXXXXXX with the photo id)