On the site, users can upload their images in any quantities (their photo albums). I keep files locally so far /files/u1/sdF/aXnKDpt2eg.jpg.

I figured out the storage space, but I don’t know how to store all this in the database. At first I thought of making a table of files with id, path fields and linking by id, but I suspect that this table will quickly swell up to several million and will work more slowly.

So wondering how best to store links to images in the database?

    1 answer 1

    And what kind of work with the base is expected? If you add a unique field with user-id and index it, then a sample of a million records will take a split second. What is the load on the project?

    Update

    Users is a finite number, right? User id is a specific user id unique for the user table. Add another field to the table with a photo, where you specify which user the photo belongs to. Index this column, then when searching for pictures for a specific user, the sample will not be taken from a million records, but only from those that belong to a specific user. All this will work very quickly if the sample request in the correct order to make.

    Avatars with albums and photos is better not to interfere, because This data is displayed with different frequencies.

    • unique will not work, because one user may have hundreds of photos. Photos are not physically deleted, even if the user deletes, simply put the flag is deleted. Unique will only id - increment. I wanted to create a table with files that does not store anything except the id and the path to the file (well, I’ll add the date of adding), and merge all the pictures (avatars, albums and just pictures), but now I understand that probably not work. - frgs
    • @Get, yes, that makes sense. probably will do so. although initially, of course, I did not want to keep connections with other tables in the table. - frgs
    • What is the point of using a relational database (for example, MySQL), if you don’t make connections between tables? Without links, indexing and the use of spent and compiled search methods that underlie the database will be really hard and slow to work. - Get
    • @Get, I did not want to keep in touch in this table, only from others. for example, so that the anonymous user could also upload something. Although an example, MB is not entirely successful, the idea is to store references to a record in other tables, for example, user . avatar or albom . cover . When the record itself does not know anything about where it comes from and where / by whom it is loaded and used. - frgs