A new model (internal/affinity) splits my listening into sittings (plays less than 30 minutes apart) and links the artists that are often played in the same sitting. It is built from my listening events and from the plays of artists I have no music of that an import kept, on my server, with no provider, and is built again when plays are added (migration 0032 keeps it as a cache). GET /me/suggestions gives two lists, each artist with the artists it goes with: the ones I have and did not play for two months, and the ones I played at least three times and have no music of. It needs discover_from_listening. POST /me/suggestions/wishlist puts an artist I played on my wishlist by name. Discover has a "From your listening" tab for both lists.
33 lines
1.1 KiB
SQL
33 lines
1.1 KiB
SQL
-- PostgreSQL flavour of sqlite/0032_affinity.sql.
|
|
|
|
CREATE TABLE affinity_builds (
|
|
user_id BIGINT PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
|
built_at BIGINT NOT NULL,
|
|
plays INTEGER NOT NULL,
|
|
sessions INTEGER NOT NULL,
|
|
artists INTEGER NOT NULL,
|
|
links INTEGER NOT NULL
|
|
);
|
|
|
|
CREATE TABLE affinity_artists (
|
|
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
artist_key TEXT NOT NULL,
|
|
name TEXT NOT NULL,
|
|
plays INTEGER NOT NULL,
|
|
sessions INTEGER NOT NULL,
|
|
last_played_at BIGINT NOT NULL,
|
|
weight DOUBLE PRECISION NOT NULL,
|
|
PRIMARY KEY (user_id, artist_key)
|
|
);
|
|
|
|
CREATE INDEX idx_affinity_artists_weight ON affinity_artists(user_id, weight DESC);
|
|
|
|
CREATE TABLE affinity_links (
|
|
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
a_key TEXT NOT NULL,
|
|
b_key TEXT NOT NULL,
|
|
score DOUBLE PRECISION NOT NULL,
|
|
PRIMARY KEY (user_id, a_key, b_key)
|
|
);
|
|
|
|
CREATE INDEX idx_affinity_links_b ON affinity_links(user_id, b_key);
|