feat: record explicit relationships between books #9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/explicit-relationships"
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?
Explicit relationships
Records relationships between different books: split volumes, collections/box sets and companions (study guides, summaries, adaptations). Same-book equivalence stays out of scope (canonical book mapping).
Changes
book_relationship, migration0012): source/target work ID (Open Library or the reader's ownmanual:ID),kind(part_of,contains,adaptation_of,study_guide_for, plusnot_relatedfor rejected suggestions),provenance, optionalposition, title snapshots,created_by/created_at. A unique index on the unordered pair keeps one record per pair, so a correction replaces it whichever direction it had.server/utils/book-relationships.ts). They only use the books already in the response:extractPart) plus the same base title and a shared author →part_of, with the part number as position;containsfor books of the same author named in the title/subtitle;study_guide_for/adaptation_offor the book named in the title.GET /api/books/searchandGET /api/libraryreturnrelationships(stored and suggested, withprovenanceandbasis) andcollectionHints, ready for the later "Cleaner search results" grouping (no grouping here).POST /api/relationships,DELETE /api/relationships/:id.BookLibraryGrid):Decisions
manual:books requires owning them.containsis not the inverse ofpart_of: a box set bundles complete books, while a split volume is a fragment of one. The two are displayed and counted differently.manualrow. Not related recordsnot_related, so the suggestion stays hidden. Storing heuristic rows would persist guesses from one search page and mix them with reader decisions. Theheuristicprovenance value is reserved for future persisted classifications (e.g. catalogue import), which manual rows override. Any stored record wins for its pair, and a book manually placed as a part or companion gets no competing suggestion.subjectin the same single query, which changes the search cache key once. Relationship reads are one DB query per search/library response.Investigation cases
Verification
pnpm lint-fullpasses.manual:ID (404), unknown delete (404), and a reverse-direction correction replacing the pair.Demo
Demo video
Review of the six commits on
feat/explicit-relationshipsagainstgit merge-base origin/master HEAD; excludes the unrelated same-book mapping PR. Reviewed endpoint validation/authorization, persistence, suggestion generation and client integration.pnpm lint-fullpasses. No repository files changed.Security — 1 finding
[P1] Filter relationships involving private manual books by ownership — must fix before merge.
Location:
server/utils/book-relationships.ts:149–159(also called byserver/api/books/search.get.ts:30andserver/utils/library.ts:74).saveBookRelationshipchecks ownership ofmanual:books, butbookRelationshipsForhas no reader identity and returns every stored relationship touching any requested work. If Alice links her private manually added manuscript to an Open Library work, Bob can search for that public work (or save it in his library) and receive Alice's manual-book ID and title snapshot, plus the relationship ID. This violates the stated rule that manual books are visible only to their owner. Read-only execution of the actual helper with a representative stored row confirms that the private title is returned for a response containing only the public work. Pass the authenticated reader through the read path and exclude links unless they own every manual endpoint; keep this filtering on the server so it also protects API/SSR payloads.Important — 2 findings
[P2] Load stored relationships for author/series results — must fix before merge.
Location:
app/components/book/BookLibraryGrid.vue:20;server/utils/author-bibliography.ts:138–149;app/components/author/AuthorBibliographyGroup.vue:11–14;app/components/book/BookBibliography.vue:81–85.The new Related menu is rendered on author and series cards, but those callers never provide relationships, and their APIs never call
bookRelationshipsFor. The grid can therefore retrieve existing records only through the reader's saved library. Reproduction: with neither book saved, open an author page and mark one displayed book as a part/companion of another. The link appears through the local override; reload the page and it disappears, including its Remove action, despite still existing in the database. Other readers browsing that author never see the correction either. Return and pass relationship data for these result sets (one batched lookup, without new upstream requests).[P2] Preserve rejection records when merging independently cached responses — must fix before merge.
Location:
server/utils/book-relationships.ts:154–161;app/composables/useBookRelationships.ts:9–22;app/components/book/BookLibraryGrid.vue:20.The server strips
not_relatedrecords entirely, so a fresh response cannot override a rejected suggestion retained in the other response cache. For example, a reader has search results and library data containing the same suggested pair; another reader rejects it. Refreshing library data now correctly omits the pair, but the grid merges the old search suggestion back in. The reverse happens when refreshing search while the library cache still contains the suggestion. The first reader can then Confirm this obsolete suggestion and overwrite the rejection. Executing the actual client merge with a cached suggestion plus the fresh empty relationship list reproduces the resurrection. Return rejected-pair tombstones (or equivalent suppression metadata) and apply them across both sources before displaying suggestions, rather than treating omission as authoritative rejection.Nit picks — 0
Pre-existing — 0
Additional checks: relationship writes validate kind, distinct work IDs and bounded positions; unordered uniqueness is enforced in PostgreSQL, and saving a correct manual link replaces an earlier
not_relatedrow. Deletion by any signed-in reader follows the stated shared-catalog policy. Suggestion computation makes no upstream calls and relationship reads use one batch query, without an N+1 lookup. Addingsubjectchanges search cache keys, so existing cached searches incur a new upstream fetch on first use; it does not add a second request per search. Author responses currently perform no relationship suggestion computation at all, as described above.96f7634432tof4aa297e6eThanks for the review. All three findings are accepted and fixed. The branch is rebased on master (#8 same-book mappings), and the relationship migration is regenerated as
0013_cold_gravity.sql, chained to master's0012.[P1] Manual-book privacy (
10bb78d)bookRelationshipsForandremoveBookRelationshipnow take the reader's ID. Stored rows are filtered server-side so a reader only sees rows where they own everymanual:endpoint. This covers search, library, author and series payloads, including SSR.[P2] Author/series pages (
25cfe97,f4aa297)BookBibliographyandAuthorBibliographyGrouppass it to the grid, so links made there persist after reload and are visible to other readers./api/authors/OL1394865A.[P2] Rejected pairs across cached responses (
9bfbbcd)rejectedPairs(visiblenot_relatedpair keys).Docs are updated (
d1b4c5f). Also adapted during the rebase:pnpm lint-fullpasses. All 14 migrations apply to a fresh clone. In the browser, Words of Radiance suggestions and a manual "part of" link still work next to the new same-book control, and the link persists after reload.