Z
Z
z0ng2019-05-04 14:04:01
PostgreSQL
z0ng, 2019-05-04 14:04:01

What is the best way to organize a database for playlists with music?

For the sake of practice, I decided to make a simple Django service with which a person can create playlists of their favorite songs.
Approximate work logic:
There is a table containing the names of all songs of all users, a table of users, a table with playlists of all users. There is also an intermediate table for linking songs to playlists.
When a user registers, a hidden playlist is created for him, where all his tracks are added (even if he did not select a single playlist). When a user adds a track that is not yet in the database, it is added to the main track database and linked to the user through a hidden playlist. If the track is in the database, then it is simply attached to the user. At first glance, nothing complicated.
The problems started when it became necessary to sort the tracks by the date they were added for each user separately. It is necessary that when selecting the tracks go in the order of addition by each individual user, both in the general playlist of the user and in the child ones.
I have 2 ideas how to do it:

  1. Add date field to hidden playlist
  2. In general, remove hidden playlists, create an intermediate table with foreign keys for the user and track, as well as the date of addition

Which option is better to choose? It is very important that the selection works quickly with a large number of users, tracks and playlists.
Thanks for answers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2019-05-04
@z0ng

I would build on the simplicity of building select queries with sorting. As for me, here is the easiest option number 1, add a date field to the playlist. Then you can simply ORDER BY on an indexed field without any additional links.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question