There is a situation in which we can have a VARCHAR field for users's avatar and store their image name in that field like most of the apps.
The other approach which I'm interested in is removing that field and store user's avatar in a folder like avatars in which avatar's file name is an MD5 of user id. Then all we need to do is to do a lookup in avatar's folder to see is there any MD5(userid) in there, if there is not then we show the default picture.
The question is which approach would be more efficient for a huge social networking site, looking around in avatar's folder or avatar field in user table?
I should also note that we have folders based on date for example we have a folder in the name of 1000 and then another folder with the name of 2000. For example /avatar/1000 contains one thousand picture, and so on.

有帮助吗?

解决方案

Having a single call to the database would be more efficient than having the call to pull back the user details from the database and a separate call to the file system check if a file exists.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top