Reputation: 3
I'm working with a huge amount of images almost quantity of 1,000,000 and all these images are owned by different users. They are all kept in a file system. I'm looking for the best way to get the right image(s) when the user log in to the website. I have to find the logged user's image(s) and load it to the user's profile.
When a new user comes to the website, he uploads his image(s) to the system and I save the image(s)to the file system like below;
If the user does not exist I create a folder named userId_username
and keep the image(s) in there.
If the user does exist then I add the image(s) to the user's folder.
But there are a lot of users and folders, almost 1,000,000, and so I have performance issues here to find the right image.
Upvotes: 0
Views: 116
Reputation: 21
"If the user does not exist I create a folder named userId_username and keep the image"
So your performance issues are related to directory search. If you are creating folders and have lag on access the user picture, you should create a root directory to keep all pictures, like this, for example:
This way, you will have a relative small and easy to identify directory structure, with access speed, because any picture you will need to access, will have only 3 levels to read. As each user profile is created, you should keep an index in a file or sql database, for direct and really fast access.
Example of file or db (the one I would prefer because of indexing capabilities):
name,directory,picturename
john;c:\userpictures\march\day14;johnnywolfe.jpg
mary,c:\userpictures\november;mmmary.jpg
So you should do this to load the picture: - find user name, in file or db - get path and picture name - just load it!
There are many ways to solve this problem. This is just one of them. Hope it helps, linoZ
Upvotes: 0
Reputation: 120450
One word. Database.
This will avoid the cost of scanning the filesystem and allow you to create indexes that are more aligned to your search.
Upvotes: 4