revolver
revolver

Reputation: 3

How can I find the right image in 1,000,000 images on a file system?

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

Answers (2)

linoZ
linoZ

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:

  1. c:\userpictures
  2. c:\userpictures\january
  3. c:\userpictures\january\day01 ... etc
  4. c:\userpictures\december\day31

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

spender
spender

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

Related Questions