chore(sqlc): delete 21 dead sqlc queries + companion dead code (bookshelf-9snmz.1.1) #1254
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "bd-bookshelf-9snmz.1.1"
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?
Summary
shelves.ListBooks,hardcoversync.SyncUserBooks/pushBooks) — required to keep compilation clean; both superseded by scoped/workflow variantsmake sqlc; moveListBookFilesByLibraryRowstruct intolibrary_scan_extra.go(liveStreamBookFilesByLibrarystill uses it, but the buffered sqlc query was dead)Deleted queries:
AppendTaskLog,ListTaskLogsAfter,Ping,ListBooksOnShelf,CountBooksOnShelf,ShelfBookExists,ListUserBooksForHardcoverSync,RevokeRefreshTokenAtomic,GetAllUserIDs,GetAllLibraryIDs,IsAppMigrationDone,MarkAppMigrationDone,SetGoodreadsIDLocked,StatsTopCategories,ListBookdropFilesByStatus,UpdateBookdropFileWithError,DeleteBookdropFile,ListBookFilesByLibrary,UpdateBookScannedOn,UpdateBookStatus(wrote bannedbook.read_status),UpsertEmailProviderPreferenceTest plan
make sqlcregenerates cleanlymake testpasses (all 50 packages green)make coveragegate passes (100% maintained)go build ./...compiles cleanlygit grepexcluding_test.goandinternal/db/sqlc/Closes bead bookshelf-9snmz.1.1 on merge.
Code Review — bd-bookshelf-9snmz.1.1 (Deletion PR)
Summary: Verified all 21 deleted sqlc queries and 2 deleted domain functions have zero production callers.
Deletion Safety Verification
Deleted sqlc queries (all confirmed dead):
ListBookdropFilesByStatus— no production callers (only in deleted integration test)UpdateBookdropFileWithError— no production callers (only in deleted integration test)DeleteBookdropFile— no production callers (only in deleted integration test)UpdateBookStatus— no production callers (only in deleted integration test)ListBookFilesByLibrary— no production callers (only in deleted integration test); streaming variantStreamBookFilesByLibraryremains and is actively used bylibrary/scanUpdateBookScannedOn— no production callers (only in deleted integration test)SetGoodreadsIDLocked— no production callersListBooksOnShelf— no production callers (only in deleted testshelves/service_test.go)CountBooksOnShelf— no production callersShelfBookExists— no production callersStatsTopCategories— no production callersRevokeRefreshTokenAtomic— no production callersGetAllUserIDs— no production callersGetAllLibraryIDs— no production callersIsAppMigrationDone— no production callersMarkAppMigrationDone— no production callersListUserBooksForHardcoverSync— no production callers (only used by deletedSyncUserBooks); paginated variantListUserBooksForHardcoverSyncPageremains and is actively used by workflowsUpsertEmailProviderPreference— no production callersListBookdropFilesByStatusParams,ListBooksOnShelfRow,ListUserBooksForHardcoverSyncRow, etc.) — properly cleanedDeleted domain functions (all confirmed dead):
shelves.ListBooks(47 LOC) — no production callers; scoped-variantListBooksScopedremainshardcoversync.SyncUserBooks(52 LOC) — no production callers; only called by deleted testhardcoversync.pushBooks(56 LOC) — private helper, only called by deletedSyncUserBooksStruct Move Verification
✓
ListBookFilesByLibraryRowcorrectly moved from generatedlibrary_scan.sql.gotolibrary_scan_extra.gowith proper documentation✓ Struct is still actively used by
StreamBookFilesByLibrary(hand-written streaming path)✓ Comment updated to reflect query deletion
✓ No orphaned field references
Integration Tests Deleted
✓
internal/db/bookdrop_integration_test.go— deletes 2 Describe blocks (40 LOC) testing only deleted queries✓
internal/db/books_integration_test.go— deletes 1 Describe block (18 LOC) testingUpdateBookStatus✓
internal/db/scan_integration_test.go— deletes 1 Describe block (75 LOC) testingListBookFilesByLibraryandUpdateBookScannedOn✓
internal/hardcoversync/service_test.go— deletes SyncUserBooks & pushBooks tests (206 LOC)✓
internal/shelves/service_test.go— deletes ListBooks test blocks (79 LOC)✓ All deleted tests are only for the deleted functions; no shared test utilities removed
Code Quality
✓ Build passes (
go build ./cmd/pergamum)✓ Unused import removed:
timefromhardcoversync/service.go✓ Duplicate comment removed from
library_scan_extra.go✓ No stray references or incomplete deletions
✓ sqlc regeneration consistent (no dangling const/type definitions)
Coverage Impact
✓ Coverage maintained: only tests for dead code deleted (no regression)
✓ Live paginated query variants (
ListBookdropFilesByStatusAfter,ListUserBooksForHardcoverSyncPage,StreamBookFilesByLibrary) remain with their own coverageREVIEW VERDICT: 0 blockers, 0 majors, 0 minors
All deletions are safe. No production callers identified for any removed code. Integration tests properly paired with their deleted targets. The PR is merge-ready.
Security re-review — PR #1247 (
bd-bookshelf-t582g.9)Re-review of the XFF-hop MAJOR fix (leftmost -> rightmost X-Forwarded-For hop). The MAJOR is CLOSED. Verification against the four criteria:
(1) Trusted mode now keys on the rightmost (proxy-appended) hop — CONFIRMED.
internal/audit/recorder.go:167switchedstrings.Index(xff, ",")(leftmost) tostrings.LastIndex(xff, ",")returningxff[idx+1:](rightmost). X-Real-IP is still preferred when present. A client-supplied leftmost value no longer influences the key, and a spoof-resistance test proves it:internal/users/ratelimiter_test.go— "a spoofed leftmost XFF value does not change the rate-limit key" asserts"attacker-spoof, 10.0.0.2"and"different-spoof, 10.0.0.2"produce the same key, plus "gives different real client IPs separate rate-limit buckets" proves distinct rightmost hops still separate. Audit-side mirror test updated to10.0.0.1(rightmost) inrecorder_test.go.(2) Untrusted mode still ignores XFF entirely — CONFIRMED.
extractIPWithPolicyonly consults headers insideif trustProxyHeaders; otherwise it falls straight tonet.SplitHostPort(r.RemoteAddr). Covered by "ignores X-Forwarded-For when trust is disabled" and "ignores X-Real-IP when trust is disabled" (ratelimiter_test.go).(3) Shared-helper change did not break audit trust semantics — CONFIRMED.
The audit
Middlewarecall site (recorder.go:96) is unchanged and still passes its owntrustProxyHeadersparam, sourced from the samecfg.TrustProxyHeaders(app.go:938) that now feeds the rate limiter (wire.go:99/158/249). Audit and rate-limit trust are unified. Audit tests updated consistently (Describe renamed to "rightmost", assertion flipped to the appended hop). No leftover single-argclientIP(r)/ExportClientIP(r)callers remain.(4) Single-trusted-hop assumption documented + multi-proxy limitation noted — CONFIRMED.
extractIPWithPolicydoc block (recorder.go:147-160) states the single-trusted-proxy rationale and calls out the multi-hop (CDN + reverse proxy) limitation as separately tracked. Config flag help (config.go:548) scopes it to "ONLY behind a trusted reverse proxy". Follow-up-acceptable per the task.IPv6 note:
LastIndex(",")is safe — XFF entries are comma-separated addresses with no intra-address comma, so the rightmost hop is extracted correctly.Findings
[MINOR] internal/audit/recorder.go:64 — stale doc comment on
MiddlewareThe
Middlewaredoc's "IP extraction policy" still reads "trustProxyHeaders=true: X-Real-IP preferred, then first X-Forwarded-For hop." The behavior is now the rightmost (proxy-appended) hop. Update "first" -> "rightmost (proxy-appended)" to match the implementation and theextractIPWithPolicydoc. Doc-only, no correctness impact.REVIEW VERDICT: 0 blocker, 0 major, 1 minor
Security Review — PR #1254 (dead-code deletion)
Reviewed
git diff origin/main...origin/bd-bookshelf-9snmz.1.1: deletion of 21 unused sqlc queries + 2 dead domain functions (shelves.ListBooks,hardcoversync.SyncUserBooks/pushBooks) + companion tests, plus a re-home of one struct.Verification performed (all clean):
shelves.ListBooks(unscoped) removal — no footgun, no lost path. The production shelf-listing path isListBooksScoped(library-scoped + content-restriction enforced in SQL), which survives with its unit + integration tests. The deletedListBooksand its underlyingListBooksOnShelf/CountBooksOnShelf/ShelfBookExistssqlc queries had zero live callers. Deleting the unscoped variant removes a cross-user footgun rather than a needed path — aligns with the multi-user hard rule.hardcoversync.SyncUserBooks/pushBooksremoval — no dangling route/handler, no orphaned auth gate.POST /account/hardcover/syncis served bysyncHandler, which enqueues the go-workflowsStartHardcoverSyncWorkflow(paginatedListUserBooksForHardcoverSyncPagepath) — NOT the deleted in-process function. Handler still enforces auth (user.ID == 0 -> ErrUnauthorized) and user-scoping (userID from session).SyncUserBookshad zero non-test callers.UpdateBookStatus/ legacybook.read_statuswriter removal — aligns with per-user rule. No remainingUPDATE book ... SET read_statuswriter exists; per-user status lives inuser_book_progress.GetBookretains independent coverage (the deleted block only read via GetBook to verify the deleted writer).RevokeRefreshTokenAtomicremoval — no auth control lost. It had zero callers on main. Surviving revocation:RevokeRefreshToken(single) +RevokeAllUserRefreshTokens(user-scopedWHERE user_id = ?).ListBookFilesByLibraryRowre-home is correct. The deleted buffered query owned the row struct the surviving streaming scan (StreamBookFilesByLibrary) depends on; the PR re-homes the struct into hand-maintainedlibrary_scan_extra.goand the streaming scan path still compiles/uses it.ListBookdropFilesByStatus,UpdateBookdropFileWithError,DeleteBookdropFile,UpsertEmailProviderPreference,SetGoodreadsIDLocked,UpdateBookScannedOn,StatsTopCategories,GetAllUserIDs,GetAllLibraryIDs,IsAppMigrationDone,MarkAppMigrationDone) — confirmed zero non-generated, non-test callers.Findings:
[MINOR] internal/db/sqlc/metadata_extra.go:232 — stale doc comment references deleted query
The
SetHardcoverBookIDcomment still citesListUserBooksForHardcoverSync(deleted in this PR) as the reader ofhardcover_book_id. Cosmetic only; update to the survivingListUserBooksForHardcoverSyncPage/GetUserBookForHardcoverSyncto avoid a dangling name.No injection, SSRF, cross-user leak, auth-gate, or read_status regressions. No CSP surface (no template/CSS changes).
REVIEW VERDICT: 0 blocker, 0 major, 1 minor
b1adf5f4a664ee971164