SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot milenko1054's Avatar
    Join Date
    Jan 2004
    Location
    Ohio
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RoR - Displaying an image from the database and server load

    I'm displaying a list of records from a database and each has an image thumbnail. I'm storing the image data in the database and using a function in the controller to serve the image:

    Code:
       def thumb
        @a = A.find(params[:id]) 
        send_data(@a.thumb_filedata,
                  :filename => @a.name,
                  :type => @a.thumb_content_type,
                  :disposition => 'inline')
      end
    Everything works fine, just have a question about server load. As I'm loading each object to display it's information in a list then calling the 'thumb' function to get the thumbnail, it looks like I'm loading each object twice to display it once in the list.

    Is this the case?

    If so, this obviously this isn't desirable - any suggestions on displaying the thumbnail from binary data in the database without loading the object twice or will I have to change to an image upload?


  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this the case?
    Yes.

    any suggestions
    You could save the images & thumbnails in files. This is not harder than in a database.

  3. #3
    SitePoint Zealot milenko1054's Avatar
    Join Date
    Jan 2004
    Location
    Ohio
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, saving in the database works better for this app from a maintenance standpoint but not at the expense of doubling the load...

    Thanks



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •