Topic: Where to store a user's picture


my users want to be able to upload a picture and show it in their profile. It's just one picture per user.

For security/backup-reasons I want to store the bitmaps in the MySql database as a blob.

The question is now how to efficiently model the user and his bitmap. Nearly all my requests are read only and efficient caching of the bitmap is possible. But should I really put the blob into the user table, resulting in useless network traffic from the db, or should I put it into a separate table that has a 1:1 relationship to the user.

I need the image only on one single page and there are many other finder methods that list users without their image. For performance reasons I don't want to load the bitmaps if I don't need them at all.

Any thoughts on this ?

Re: Where to store a user's picture

A separate table sounds like a much better solution. By default all queries fetch all columns in the table, so that would result in a lot of unnecessary data being passed around. You can use eager loading to fetch the image along with the user's data on the one page you need it to minimize database queries.

Railscasts - Free Ruby on Rails Screencasts

Re: Where to store a user's picture

Thx, ryanb, that's what I'm going to do.

Re: Where to store a user's picture

From what I've learnt it's always faster to store data on a filesystem.