An interesting question has ripened, we have a user base , each of them has the opportunity to create their own gallery , or even several.

How best , on the part of speed and reliability , to create a data storage structure. I think between the two options - to give the entire load on the database , or more on the file system .

In the first case: All photos are stored in a shared directory , links to images are placed in the database .

In the second: for each user we create our own directory in which the images are loaded, and when retrieving a photo, we simply scan it and display everything that has the appropriate resolution. In parallel, there is a database with the name of the files - for deletion.

  • Usually use the second option - Ninazu

1 answer 1

It all depends on what you need now and what prospects for the future are possible. The organization of directories in the form of пользователь/ID_альбома/файлы links the gallery to the user. In this case, it is necessary to understand whether there is a need to link the gallery to the user.

For example, galleries can be published as public. Also, what happens when a user is deleted? Should the gallery be saved?

For example, perhaps this situation. Any user can save a public gallery in their favorites. What should happen if the author of the gallery deletes your account? Should a gallery be removed from a favorite subscriber? If not, then the link account - the gallery is not correct.

For greater flexibility, you can apply this solution. In the file system, the gallery will look like albums/ album_ID/images .

The database can be organized like this.

  • A separate albums table in which there will be an entire list of albums

  • And one more user_albums table in which there will be a pair of keys user_ID,album_ID .

  • one
    Thank you, quite a universal answer - I was interested not for a specific task, but for general development, and understanding how best to bypass such a weak spot as a database - Vlad