-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Context
PR #230 added Elasticsearch as an optional search backend with a facade that routes to ES or pg_trgm. It left stub functions in elasticsearch.sync.ts for dual-write sync and bulk reindex. This issue tracks implementing those stubs, wiring dual-write into the library service layer, adding a management reindex endpoint, and providing unit tests.
Changes
elasticsearch.sync.ts — Replace stubs with implementations
indexLibraryDocumentById(albumId)— Querieslibrary_artist_viewby ID, indexes into ES. Wrapped in try/catch — logs errors, never throws.removeLibraryDocument(id)— Deletes from ES by string ID. Ignores 404.bulkIndexLibrary()— CallsensureLibraryIndex(), reads all rows fromlibrary_artist_view, chunks into batches of 500, uses ES_bulkAPI. Returns{ indexed, errors }counts.
library.service.ts — Dual-write calls
Fire-and-forget sync on:
insertAlbum— after insert, sync the new albumaddToRotation— after insert, sync the album (rotation_bin changes)killRotationInDB— after update, sync the album (kill_date removes rotation_bin)
Errors are logged but never propagated — library operations succeed even if ES is temporarily unavailable.
library.controller.ts + library.route.ts — Reindex endpoint
POST /library/reindex — requires catalog: ['write'] permission (musicDirector or stationManager). Calls bulkIndexLibrary() and returns { message, indexed, errors }.
Unit tests
- 18 tests for sync functions (client null handling, 404 ignore, batch chunking, error counting, rotation_bin mapping)
- 6 tests for dual-write behavior in library service (correct album ID passed, errors don't propagate)
What's NOT included
- Integration tests with a real ES container
- ETL job modification — operators should call
POST /library/reindexafter ETL - CI docker-compose changes — ES remains opt-in
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels