从单个文件夹中搜索文件(已知前缀)与从多个文件夹中搜索文件(已知文件夹名称)
我有一个系统,用户可以在其中选择几个选项并根据这些选项接收图像。我正在尝试将多个生成的图像(对应于这些选项)组合到请求的图片中。我正在尝试对此进行优化,以便如果某个选项存在图像(即文件存在),则无需计算它,我们将继续下一步。
我应该将这些图像存储在不同的文件夹中,其中每个文件夹都是一个选项名称吗?我应该将它们存储在同一文件夹中,并为每个图像添加与选项相对应的前缀吗?我应该将文件名存储在数据库中并在那里检查吗?哪种方法可以更快地检查文件是否存在?
我在 Linux 上使用 PHP,但如果我更改编程语言或操作系统,答案是否会有所不同,我也很感兴趣。
I've got a system in which users select a couple of options and receive an image based on those options. I'm trying to combine multiple generated images(corresponding to those options) into the requested picture. I'm trying to optimize this so that if, an image exists for a certain option (i.e. the file exists), then there's no need to compute it and we move on to the next step.
Should I store these images in different folders, where each folder is an option name? Should I store them in the same folder, adding a prefix corresponding to the option to each image? Should I store the filenames in a database and check there? Which way is faster to check a file for existence?
I'm using PHP on Linux, but I'm also interested if the answer varies if I change the programming language or the OS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要生成大量此类图像,将它们全部保存在一个平面目录中似乎不太可扩展。我会采用层次结构,这将使其更易于管理。
不过,检查数据库总是比检查文件是否存在要快,因此如果速度是主要考虑因素,请使用分层文件夹结构并将所有文件名保留在数据库中。
If you're going to be producing a lot of these images, it doesn't seem very scalable to keep them all in one flat directory. I would go with a hierarchy, which will make it a lot easier to manage.
It's always going to be quicker to check in a database than to check if a file exists though, so if speed is the primary concern, use a hierarchical folder structure and keep all the filenames in a database.