You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ensure repository/specification queries only return books that actually have at least one book-format file (isBookFormat = true).
Prevent duplicate book rows caused by joins when loading lists/pages and ensure stable API DTO lists.
Make paged results accurate when ContentRestrictionService filters out items by recomputing totals for restricted users.
Description
Tighten AppBookSpecification.hasDigitalFile to use a subquery EXISTS on BookFileEntity where isBookFormat = true instead of isNotEmpty on the collection.
Update multiple BookRepository queries (including findAllWithMetadata*, paged queries and countByLibraryId) to add an EXISTS subquery that ensures bf.isBookFormat = true and to use COUNT(DISTINCT b) where appropriate.
Add existsByUserId to UserContentRestrictionRepository and expose hasRestrictions(Long) in ContentRestrictionService to quickly detect whether a user has any restrictions.
Add deduplication logic deduplicateById(List<BookEntity>) to BookQueryService and apply it to list and paged flows, and recompute Page totals when the requesting user has content restrictions.
Add/adjust tests: extend BookRepositoryDataJpaTest with tests for countByLibraryId, hasDigitalFile spec, and findAllWithMetadata behavior; add BookQueryServiceTest to verify deduplication and restriction-aware paging behavior.
Testing
Ran repository integration tests in BookRepositoryDataJpaTest that cover countByLibraryId, hasDigitalFile spec, and findAllWithMetadata, and they succeeded.
Ran unit tests in BookQueryServiceTest covering deduplication and recomputed page totals for restricted users, and they succeeded.
Existing test suites that touch the modified repository/service code were executed and passed locally.
Deduplicate restricted totals before computing page count
When restrictions are present, totalElements is computed from applyRestrictions(allCandidates, userId).size() using findAllWithMetadataByLibraryIds, but this same query path is already being deduplicated elsewhere because it can return duplicate BookEntity rows. In those cases, page content is deduplicated while totalElements is not, so restricted users receive inflated totals and inconsistent pagination metadata. Deduplicate before counting (or switch this total to a distinct-count strategy).
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
isBookFormat = true).ContentRestrictionServicefilters out items by recomputing totals for restricted users.Description
AppBookSpecification.hasDigitalFileto use a subqueryEXISTSonBookFileEntitywhereisBookFormat = trueinstead ofisNotEmptyon the collection.BookRepositoryqueries (includingfindAllWithMetadata*, paged queries andcountByLibraryId) to add anEXISTSsubquery that ensuresbf.isBookFormat = trueand to useCOUNT(DISTINCT b)where appropriate.existsByUserIdtoUserContentRestrictionRepositoryand exposehasRestrictions(Long)inContentRestrictionServiceto quickly detect whether a user has any restrictions.deduplicateById(List<BookEntity>)toBookQueryServiceand apply it to list and paged flows, and recomputePagetotals when the requesting user has content restrictions.BookRepositoryDataJpaTestwith tests forcountByLibraryId,hasDigitalFilespec, andfindAllWithMetadatabehavior; addBookQueryServiceTestto verify deduplication and restriction-aware paging behavior.Testing
BookRepositoryDataJpaTestthat covercountByLibraryId,hasDigitalFilespec, andfindAllWithMetadata, and they succeeded.BookQueryServiceTestcovering deduplication and recomputed page totals for restricted users, and they succeeded.Codex Task