我应该检查图像文件是否存在或者数据库中是否有 hasImage 列?
我显示很多项目,每个项目都可以有一张图片,当它没有时我想显示“nopicture.jpeg”
我应该检查每个项目是否为jpeg(id.jpeg - 我将它们保存为项目的id + .jpeg)存在于硬盘上或者数据库中有一个位列?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
到磁盘上获取每个图像的成本很可能比从数据库中获取页面上所有图像的结果更昂贵,但随着非常快的 SSD 的出现,情况可能并非如此。
当然,您需要进行测试,但我首先会选择数据库列。
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.
尽管这可能是不好的做法,但为什么不将其作为查询的一部分呢?
有时,您可以运行一个脚本来验证表中的每个图像路径并删除无效路径。
Though it might be bad practice, why don't you make that part of your query?
Once in a while, you could run a script that validates each image path in your table and removes in invalid paths.
在硬盘上检查它会比较慢。我也不一定使用数据库中的实际列。在数据库中检查它并根据是否有图片返回一个列,如下所示:
CASE WHEN column_with_picture IS NULL THEN 0 ELSE 1 END AS has_picture_TF
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