Split enrichment.service.ts (and the other oversized files) #2
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #1, deliberately not done there: extracting it is a behavioural refactor rather than a move, so it would have made that PR harder to review.
The files
workers/src/enrichment.service.tsworkers/src/integrations/musicbrainz.client.tsfrontend/src/pages/Jobs.tsxWhy
enrichment.service.tsis the hard oneIt is a single class holding
private pgClient: Queryable, so splitting it means turning methods into free functions that take aQueryableexplicitly (asmergeArtistIntoinreprocess-artists.service.tsnow does), or composing sub-services the class delegates to. Either way call sites andthis.references change — not a pure move, so "diff the content byte-identical" no longer works as the safety check.Seams that look clean:
ensureSchema(78-157)resolveArtistIdentity,createLocalArtist,generateSortName,addArtistAlias,updateArtistLookupCache(213-448), plusanalyzeArtistIdentification/verifyArtistIdentity(1099-1242)getArtistImage,updateArtistImage(449-542),refreshArtistImage(873-908),refreshAlbumCover(909-1045)enrichTrack(543-838) — 295 lines on its own, the real monster, and the one that needs decomposing rather than relocatingdedupAlbums,mergeAlbum(1243-1330)Constraints when this happens
npm run typecheckis the only gate, and it will not catch aQueryablebeing passed where a transaction-scoped client was meant. Consider landing a few tests forresolveArtistIdentityanddedupAlbumsbefore moving them.enrichTrackandresolveArtistIdentityare on the hot enrichment path withconcurrency: 10; keep the transaction boundaries exactly where they are (see thePoolcommit in #1 for why a sharedBEGINis dangerous here).Line numbers above are as of
bec77f4and will drift.