[Solved] Missing photos when retrieving Users tagged photos facebook-graph API

EverSQL Database Performance Knowledge Base

Missing photos when retrieving Users tagged photos facebook-graph API

I'm trying to retrieve all of the photos that a user is tagged in from Facebook. I have both the user_photos and friends_photos access token but am not getting a full list of photos (i.e. all the photos the user is tagged in).

Below is my fql query:

SELECT images, target_type FROM photo WHERE pid IN (SELECT pid FROM photo_tag WHERE subject =" + req.user.id + ")ORDER BY created DESC

I'm rather confused as some of the photos that are not being retrieved have been uploaded publicly. Basically I am unable to see a pattern among the photos that haven been left out. Could anyone explain why some photos are being left out?

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Create Optimal Indexes (modified query below): The recommended indexes are an integral part of this optimization effort and should be created before testing the execution duration of the optimized query.
  2. Replace In Subquery With Correlated Exists (modified query below): In many cases, an EXISTS subquery with a correlated condition will perform better than a non correlated IN subquery.
Optimal indexes for this query:
ALTER TABLE `photo` ADD INDEX `photo_idx_created` (`created`);
ALTER TABLE `photo_tag` ADD INDEX `photo_tag_idx_subject_id_+__pid` (`subject`,`id + `,`pid`);
The optimized query:
SELECT
        photo.images,
        photo.target_type 
    FROM
        photo 
    WHERE
        EXISTS (
            SELECT
                1 
            FROM
                photo_tag 
            WHERE
                (
                    photo_tag.subject = photo_tag." + req.user.id + "
                ) 
                AND (
                    photo.pid = photo_tag.pid
                )
        ) 
    ORDER BY
        photo.created DESC

Related Articles



* original question posted on StackOverflow here.