Reputation: 71238
I display a lot of items, each can have a picture, when it hasn't I want to show 'nopicture.jpeg'
Should I check for each item if its jpeg (id.jpeg - i save them as id of the item + .jpeg) exists on the hard drive or have a bit column in the database for this?
Upvotes: 0
Views: 401
Reputation: 499162
Chances are good that going to the disk for each image will be more expensive than getting the results for all images on a page from the database, though with the advent of very fast SSDs this may not be the case.
You will need to test, of course, but I would go with a database column at first.
Upvotes: 1
Reputation: 12526
Checking for it on the hard drive will be slower. I wouldn't necessarily use an actual column in the db either. Check for it in the db and return a column based on whether there is a picture or not like this:
CASE WHEN column_with_picture IS NULL THEN 0 ELSE 1 END AS has_picture_TF
Upvotes: 1
Reputation: 12571
Though it might be bad practice, why don't you make that part of your query?
SELECT ISNULL( Picture, "nopicture.jpg" ) as ItemPicture From MyTable
Once in a while, you could run a script that validates each image path in your table and removes in invalid paths.
Upvotes: 1