Question

I'm using the following code to select all photos I am tagged in

select pid from photo_tag where subject = me()

but now I want to select only the photos from a certain album, there is two ways I can do this.

select pid from photo where aid = $aid1 and pid in ( select pid from photo_tag where subject = me() )

or

select pid from photo_tag where subject = me() and pid in ( select pid from photo where aid = $aid1 )

as far as im aware they both do the same thing and it's working ok.

The problem is it doesn't work so well with a second, third, etc album.

If i do the following

select pid from photo_tag where subject = me() and pid in ( select pid from photo where aid = $aid1 or aid = $aid2)

it will only select the photos from one of the albums not both, if I replace the or with and it will select the photos im tagged in from the first album and all of the photos from the second album.

So the query ends up growing into something like

 SELECT pid from photo where ( pid in (select pid from photo where aid = $aid1 and pid in (select pid from photo_tag where subject = me() ) ) or pid in (select pid from photo where aid = $aid2 and pid in (select pid from photo_tag where subject = me() ) ) )

when I do the query to get all the photos I'm tagged in it takes around 900ms and as far as I'm aware returns a few hundred photos. I'm trying to limit this to about 6 or 7 albums which is about 150 photos but I don't think the query is efficient enough as I started to run the query about 15 minutes ago and its still loading so I don't think its ever going to return anything.

Would it be quicker if I did a query for each album individually, rather than all of the albums together?

What else could be better.

I appreciate any help here.

Thanks

Was it helpful?

Solution

Start looking into multi-queries and batch this should increase your performance.

So your last query would be an array calls in batch separated by album and each call will be a multi query between the photo and photo_tag table.

https://developers.facebook.com/docs/reference/api/batch/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top