Skip to main content
Inspiring
January 12, 2011
Answered

Flickr API and cflickr - performance issue with my code.

  • January 12, 2011
  • 3 replies
  • 901 views

I using cflickr to access the Flickr api and display photos in a lightbox. My code is working, but incredibly slow. I'm assuming that I'm going about it in an incorrect way and hoping someone can point out a better way to do what I'm trying to accomplish. My speed issues develop when I'm trying to extract the image descriptions within a loop that is outputing the images to the page.

Here is an example of the code that I'm using:

using the following to grab the photos:

<cfset photos = cflickr.photosets_getPhotos(photoset_id=72157624340881708 , auth_token=token) />

I am then using the following to loop through the array of photos and and also retrieve the description for each image.

<div style="width:423px; margin: auto;" id="gallery">
        <cfloop from="1" to="#arraylen(photos.photoset.photo)#" index="i">
            <cfset p = photos.photoset.photo />
            <cfset img_desc = cflickr.photos_getInfo(photo_id=p.id).photo.description />
            <cfset img_desc = replace(img_desc, 'TRIP', '<br />TRIP') />
            <cfset title = photos.photoset.photo.title />
            <cfset title = title & "<br />" & img_desc />
            <cfoutput>
            <a href="#cflickr.getPhotoUrl(p, '')#" title="#title#"><img src="#cflickr.getPhotoUrl(p, 's')#"  /></a>
            </cfoutput>
        </cfloop>
    </div>

The problem with the code is when it is making the request for img_desc inside of the loop to the Flickr api. Each instance of that call is taking on average 300 to 400ms and the array has over 300 items so it times out. Should I be retrieveing all of the image descritpions at once before the loop and if so how would I best link these with image data that they belong with? It seems like I'm going about this in a rather inefficient manner.

I was hoping that I could call a function that retrieved all of the data that I need in one call, but so far I've been unable to find that.

    This topic has been closed for replies.
    Correct answer -__cfSearching__-

    ( Grrr... this forum trashes emails better than any application I have ever seen.  Here is what my previous response actually said ...)

    <cfset photos = cflickr.photosets_getPhotos(photoset_id=72157624340881708 , auth_token=token)>

    I cannot say I have used it. But the cfc usage seems to follow the API pretty closely. So I took a quick look at the flickr forums, and one person suggests you can grab the descriptions too by adding the "extras" parameter.


    http://www.flickr.com/groups/api/discuss/72157594456853637/#comment72157623785775034

    So try using:
        <cflickr.photosets_getPhotos(photoset_id=72157624340881708 ,
             auth_token=token, extras="description")>

    3 replies

    -__cfSearching__-Correct answer
    Inspiring
    January 12, 2011

    ( Grrr... this forum trashes emails better than any application I have ever seen.  Here is what my previous response actually said ...)

    <cfset photos = cflickr.photosets_getPhotos(photoset_id=72157624340881708 , auth_token=token)>

    I cannot say I have used it. But the cfc usage seems to follow the API pretty closely. So I took a quick look at the flickr forums, and one person suggests you can grab the descriptions too by adding the "extras" parameter.


    http://www.flickr.com/groups/api/discuss/72157594456853637/#comment72157623785775034

    So try using:
        <cflickr.photosets_getPhotos(photoset_id=72157624340881708 ,
             auth_token=token, extras="description")>

    Inspiring
    January 12, 2011

    The "extras" parameter worked perfectly. Thanks very much for the advice!

    Inspiring
    January 12, 2011

    I

    Inspiring
    January 12, 2011

    I'm not sure whether this could help you; but just thinking of using CFTHREAD; for every getInfo you could use CFTHREAD.(I'm sorry if wrong)

    May be someone will come with the best solution.