Files
minstrel/internal/db/migrations/0072_similarity_cache.up.sql
T
bvandeusenandClaude Opus 5.5 6028d78844
release / govulncheck (push) Successful in 17s
release / web (push) Successful in 1m33s
release / go (push) Successful in 1m49s
release / integration (push) Successful in 5m42s
release / android (push) Successful in 5m59s
release / Build signed APK (releases and dev) (push) Successful in 6m9s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 16s
release / Verify release artifacts (tag releases only) (push) Skipped
docs: migration headers keep the before and after, without ids, quotes or one library's numbers (#6277)
Applies rule 32's migration exception: each header still says what the
schema was, what changes and what it prevents, but task, milestone,
decision and rule ids are replaced by the practice they stood for, the
operator quotes by the decision, single-install counts are dropped, and
pointers to a deleted package and an external design doc are gone.
golang-migrate keeps no checksum, so editing applied migrations'
comments is safe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 12:34:39 -04:00

44 lines
2.0 KiB
SQL

-- Keep ListenBrainz's whole similar-recordings answer, and record every
-- fetch, so the library match is made locally and can be made again.
--
-- Before: the worker kept only the recordings already in the library (at most
-- 20 of LB's 50) and threw the rest away. Two things followed:
--
-- * A recording that reached the library later — a Lidarr import, or an MBID
-- filled in by the AcoustID lookup — was not linked until its seed was
-- fetched again.
-- * A seed with no in-library match wrote nothing at all, and freshness was
-- read from track_similarity, so that seed was never fresh. With the queue
-- ordered by id, such seeds held its head and were re-asked every hour
-- while the rest waited.
--
-- The listenbrainz rows in track_similarity are now derived from this cache by
-- ResolveListenBrainzTrackEdges.
CREATE TABLE listenbrainz_similar_recordings (
seed_track_id uuid NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
recording_mbid text NOT NULL,
score DOUBLE PRECISION NOT NULL,
PRIMARY KEY (seed_track_id, recording_mbid)
);
-- The resolve joins the cache to tracks by recording MBID.
CREATE INDEX listenbrainz_similar_recordings_mbid_idx
ON listenbrainz_similar_recordings (recording_mbid);
-- One row per seed that ListenBrainz has answered for, an empty answer
-- included. The worker's queue reads this, not the edges.
CREATE TABLE track_similarity_fetches (
track_id uuid PRIMARY KEY REFERENCES tracks(id) ON DELETE CASCADE,
fetched_at timestamptz NOT NULL DEFAULT now(),
returned integer NOT NULL
);
-- The same for artists. Their answer is already kept, in artist_similarity and
-- artist_similarity_unmatched; this only stops an empty answer being re-asked.
CREATE TABLE artist_similarity_fetches (
artist_id uuid PRIMARY KEY REFERENCES artists(id) ON DELETE CASCADE,
fetched_at timestamptz NOT NULL DEFAULT now(),
returned integer NOT NULL
);