refactor(db): GetCollectionItemsForDashboard embeds the media row; excluded filter moves into SQL; third converter dies
SELECT mi.*, ci.excluded forced every caller to filter tombstone exclusions in Go over a 69-field row, then a 45-field hand converter (getCollectionItemsRowToMediaItems) copied it field-by-field into MediaItems for BuildSections. The query now filters (ci.excluded IS NOT TRUE) itself and returns sqlc.embed(mi) — callers consume .MediaItems directly, the Go filter loops die in both collection-detail ladders (JSON + SSR), and the converter is deleted. Pins, H1/H3 tests, unit suites green.
This commit is contained in:
1 parent
18727fef93
commit
77cf0b827b
7 files changed
+102
-218
No files matched your search
+11
-10
@@ -125,20 +125,21 @@ func BookCardsFromMediaItems(rows []database.MediaItems, libTypes map[string]str
|
||||
}
|
||||
|
||||
// BookCardsFromCollectionDashRows builds cards from the
|
||||
// collection-items join (GetCollectionItemsForDashboard). The row's ID
|
||||
// IS the media item id. The Excluded filter stays at call sites — only
|
||||
// the two collection-detail surfaces exclude tombstones.
|
||||
// collection-items join (GetCollectionItemsForDashboard). The query
|
||||
// embeds the media row and filters excluded rows in SQL, so the adapter
|
||||
// reads through the embed.
|
||||
func BookCardsFromCollectionDashRows(rows []database.GetCollectionItemsForDashboardRow, libTypes map[string]string) []BookInfo {
|
||||
cards := make([]BookInfo, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
mi := r.MediaItems
|
||||
cards = append(cards, buildBookCard(cardSource{
|
||||
ID: uuid.UUID(r.ID.Bytes),
|
||||
Title: r.Title,
|
||||
Author: utils.PgTextString(r.Author),
|
||||
LibraryID: r.LibraryID,
|
||||
CoverPath: r.CoverImagePath,
|
||||
FormatGroup: r.FormatGroup,
|
||||
LibraryType: libTypes[uuid.UUID(r.LibraryID.Bytes).String()],
|
||||
ID: uuid.UUID(mi.ID.Bytes),
|
||||
Title: mi.Title,
|
||||
Author: utils.PgTextString(mi.Author),
|
||||
LibraryID: mi.LibraryID,
|
||||
CoverPath: mi.CoverImagePath,
|
||||
FormatGroup: mi.FormatGroup,
|
||||
LibraryType: libTypes[uuid.UUID(mi.LibraryID.Bytes).String()],
|
||||
}))
|
||||
}
|
||||
return cards
|
||||
|
||||
Reference in new issue
Block a user