Answer the question
In order to leave comments, you need to log in
How to store data in a database?
There is a list of 100K users with unique IDs stored in the database.
There is a list of 100K images with unique IDs stored in a database.
Users go to the site and view the images in the gallery, which consists of all the images from the database.
The user cannot access an arbitrary image of the gallery. It can only transition to the two nearest images from the current one (prev, next).
In this case, the user should not see the previously viewed image again if there are still images that he has not seen.
Questions.
one). How to store information about the list of viewed / not yet viewed images by a specific user? How to quickly select images for viewing? (I'm thinking about prefetching images for each user for their next call).
2). What stack to use? SQL/NoSQL?
Answer the question
In order to leave comments, you need to log in
1) in addition to the ID, I would also store a serial number that would clearly define the sequence of images. In this case, we can store ranges of unviewed images. Well, since we can only go to the neighboring image, this is easy to arrange.
2) doesn't matter. It is better to take sql and nosql by default for caching and data aggregation if necessary.
Check if prev/next gives a random id or a neighboring one? If adjacent, then it turns out that all the images that the user has viewed form the id range.
If so, then for each user, you need to store the min / max id of the image that he has already viewed, as well as his current position.
The relational database would have the following table:
user id, min_image_id, max_image_id, current_image_id
Then, when the user clicks prev/next, it is necessary to find the image following the current one in the image table and update the user's state.
In general, you can store all the images that the user has viewed, this will not change the essence, it just takes more space.
You can make such a thing on anything, I can tell you how to do it on the Tarantula.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question