fix(books): include physical books in app book list query (#938)

This commit is contained in:
Anton Isaiev
2026-05-04 02:58:04 -04:00
committed by GitHub
parent de932000e2
commit 218ebb4e03
3 changed files with 24 additions and 17 deletions
@@ -247,7 +247,7 @@ public class AppBookService {
Specification<BookEntity> spec = AppBookSpecification.combine( Specification<BookEntity> spec = AppBookSpecification.combine(
AppBookSpecification.notDeleted(), AppBookSpecification.notDeleted(),
AppBookSpecification.hasDigitalFile(), AppBookSpecification.hasDigitalFileOrIsPhysical(),
AppBookSpecification.inLibraries(accessibleLibraryIds), AppBookSpecification.inLibraries(accessibleLibraryIds),
AppBookSpecification.searchText(query) AppBookSpecification.searchText(query)
); );
@@ -311,7 +311,7 @@ public class AppBookService {
Specification<BookEntity> spec = AppBookSpecification.combine( Specification<BookEntity> spec = AppBookSpecification.combine(
AppBookSpecification.notDeleted(), AppBookSpecification.notDeleted(),
AppBookSpecification.hasDigitalFile(), AppBookSpecification.hasDigitalFileOrIsPhysical(),
AppBookSpecification.inLibraries(accessibleLibraryIds), AppBookSpecification.inLibraries(accessibleLibraryIds),
AppBookSpecification.addedWithinDays(30) AppBookSpecification.addedWithinDays(30)
); );
@@ -404,7 +404,7 @@ public class AppBookService {
List<AppBookSummary> summaries = orderedBookIds.stream() List<AppBookSummary> summaries = orderedBookIds.stream()
.map(bookEntitiesById::get) .map(bookEntitiesById::get)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.filter(BookEntity::hasFiles) .filter(b -> b.hasFiles() || Boolean.TRUE.equals(b.getIsPhysical()))
.map(bookEntity -> mobileBookMapper.toSummary(bookEntity, progressMap.get(bookEntity.getId()))) .map(bookEntity -> mobileBookMapper.toSummary(bookEntity, progressMap.get(bookEntity.getId())))
.toList(); .toList();
@@ -573,7 +573,7 @@ public class AppBookService {
"FROM UserBookProgressEntity ubp " + "FROM UserBookProgressEntity ubp " +
"WHERE ubp.user.id = :userId AND ubp.personalRating IS NOT NULL " + "WHERE ubp.user.id = :userId AND ubp.personalRating IS NOT NULL " +
"AND ubp.book.id IN (SELECT b.id FROM BookEntity b WHERE (b.deleted IS NULL OR b.deleted = false) " + "AND ubp.book.id IN (SELECT b.id FROM BookEntity b WHERE (b.deleted IS NULL OR b.deleted = false) " +
"AND b.bookFiles IS NOT EMPTY " + "AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true) " +
scopeClause + ") " + scopeClause + ") " +
"GROUP BY 1 ORDER BY 1 DESC"; "GROUP BY 1 ORDER BY 1 DESC";
var prQ = entityManager.createQuery(personalRatingQuery, Tuple.class); var prQ = entityManager.createQuery(personalRatingQuery, Tuple.class);
@@ -624,7 +624,7 @@ public class AppBookService {
String creatorJpql = "SELECT cr.name, mapping.role, COUNT(DISTINCT b.id) FROM BookEntity b" String creatorJpql = "SELECT cr.name, mapping.role, COUNT(DISTINCT b.id) FROM BookEntity b"
+ " JOIN b.metadata m JOIN m.comicMetadata cm JOIN cm.creatorMappings mapping JOIN mapping.creator cr" + " JOIN b.metadata m JOIN m.comicMetadata cm JOIN cm.creatorMappings mapping JOIN mapping.creator cr"
+ " WHERE (b.deleted IS NULL OR b.deleted = false)" + " WHERE (b.deleted IS NULL OR b.deleted = false)"
+ " AND b.bookFiles IS NOT EMPTY" + " AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true)"
+ " " + scopeClause + " " + scopeClause
+ " GROUP BY cr.name, mapping.role ORDER BY COUNT(DISTINCT b.id) DESC"; + " GROUP BY cr.name, mapping.role ORDER BY COUNT(DISTINCT b.id) DESC";
var creatorQ = entityManager.createQuery(creatorJpql, Tuple.class); var creatorQ = entityManager.createQuery(creatorJpql, Tuple.class);
@@ -800,7 +800,7 @@ public class AppBookService {
List<Specification<BookEntity>> specs = new ArrayList<>(); List<Specification<BookEntity>> specs = new ArrayList<>();
specs.add(AppBookSpecification.notDeleted()); specs.add(AppBookSpecification.notDeleted());
specs.add(AppBookSpecification.hasDigitalFile()); specs.add(AppBookSpecification.hasDigitalFileOrIsPhysical());
if (accessibleLibraryIds != null) { if (accessibleLibraryIds != null) {
if (req.libraryId() != null && accessibleLibraryIds.contains(req.libraryId())) { if (req.libraryId() != null && accessibleLibraryIds.contains(req.libraryId())) {
@@ -1105,7 +1105,7 @@ public class AppBookService {
private Specification<BookEntity> buildBaseSpecification(Set<Long> accessibleLibraryIds, Long libraryId) { private Specification<BookEntity> buildBaseSpecification(Set<Long> accessibleLibraryIds, Long libraryId) {
List<Specification<BookEntity>> specs = new ArrayList<>(); List<Specification<BookEntity>> specs = new ArrayList<>();
specs.add(AppBookSpecification.notDeleted()); specs.add(AppBookSpecification.notDeleted());
specs.add(AppBookSpecification.hasDigitalFile()); specs.add(AppBookSpecification.hasDigitalFileOrIsPhysical());
if (accessibleLibraryIds != null) { if (accessibleLibraryIds != null) {
if (libraryId != null && !accessibleLibraryIds.contains(libraryId)) { if (libraryId != null && !accessibleLibraryIds.contains(libraryId)) {
@@ -1155,7 +1155,7 @@ public class AppBookService {
String jpql = "SELECT " + selectExpr + ", COUNT(DISTINCT b.id) FROM BookEntity b" String jpql = "SELECT " + selectExpr + ", COUNT(DISTINCT b.id) FROM BookEntity b"
+ " " + joins + " " + joins
+ " WHERE (b.deleted IS NULL OR b.deleted = false)" + " WHERE (b.deleted IS NULL OR b.deleted = false)"
+ " AND b.bookFiles IS NOT EMPTY" + " AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true)"
+ (extraWhere.isEmpty() ? "" : " " + extraWhere) + (extraWhere.isEmpty() ? "" : " " + extraWhere)
+ " " + scopeClause + " " + scopeClause
+ " GROUP BY " + selectExpr + " ORDER BY COUNT(DISTINCT b.id) DESC"; + " GROUP BY " + selectExpr + " ORDER BY COUNT(DISTINCT b.id) DESC";
@@ -1208,7 +1208,7 @@ public class AppBookService {
+ " AND ubp.book.id IN (" + " AND ubp.book.id IN ("
+ " SELECT b.id FROM BookEntity b" + " SELECT b.id FROM BookEntity b"
+ " WHERE (b.deleted IS NULL OR b.deleted = false)" + " WHERE (b.deleted IS NULL OR b.deleted = false)"
+ " AND b.bookFiles IS NOT EMPTY" + " AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true)"
+ " " + scopeClause + " " + scopeClause
+ " )" + " )"
+ " GROUP BY ubp.readStatus ORDER BY COUNT(DISTINCT ubp.book.id) DESC"; + " GROUP BY ubp.readStatus ORDER BY COUNT(DISTINCT ubp.book.id) DESC";
@@ -1223,7 +1223,7 @@ public class AppBookService {
String baseQuery = "SELECT COUNT(DISTINCT b.id) FROM BookEntity b" String baseQuery = "SELECT COUNT(DISTINCT b.id) FROM BookEntity b"
+ " WHERE (b.deleted IS NULL OR b.deleted = false)" + " WHERE (b.deleted IS NULL OR b.deleted = false)"
+ " AND b.bookFiles IS NOT EMPTY" + " AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true)"
+ " AND b.id NOT IN (" + " AND b.id NOT IN ("
+ " SELECT ubp.book.id FROM UserBookProgressEntity ubp WHERE ubp.user.id = :userId" + " SELECT ubp.book.id FROM UserBookProgressEntity ubp WHERE ubp.user.id = :userId"
+ " )" + " )"
@@ -1262,7 +1262,7 @@ public class AppBookService {
String scopeClause, Set<Long> accessibleLibraryIds, String scopeClause, Set<Long> accessibleLibraryIds,
Long libraryId, Long shelfId, Set<Long> magicBookIds) { Long libraryId, Long shelfId, Set<Long> magicBookIds) {
String jpql = "SELECT " + caseExpr + ", COUNT(DISTINCT b.id) FROM BookEntity b " + joins + String jpql = "SELECT " + caseExpr + ", COUNT(DISTINCT b.id) FROM BookEntity b " + joins +
" WHERE (b.deleted IS NULL OR b.deleted = false) AND b.bookFiles IS NOT EMPTY " " WHERE (b.deleted IS NULL OR b.deleted = false) AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true) "
+ extraWhere + " " + scopeClause + + extraWhere + " " + scopeClause +
" GROUP BY 1"; " GROUP BY 1";
var q = entityManager.createQuery(jpql, Tuple.class); var q = entityManager.createQuery(jpql, Tuple.class);
@@ -80,7 +80,7 @@ public class AppSeriesService {
+ " FROM BookEntity b JOIN b.metadata m" + " FROM BookEntity b JOIN b.metadata m"
+ " LEFT JOIN b.userBookProgress p ON p.user.id = :userId" + " LEFT JOIN b.userBookProgress p ON p.user.id = :userId"
+ " WHERE (b.deleted IS NULL OR b.deleted = false)" + " WHERE (b.deleted IS NULL OR b.deleted = false)"
+ " AND b.bookFiles IS NOT EMPTY" + " AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true)"
+ " AND m.seriesName IS NOT NULL" + " AND m.seriesName IS NOT NULL"
+ libraryClause + libraryClause
+ searchClause + searchClause
@@ -103,7 +103,7 @@ public class AppSeriesService {
String countQuery = "SELECT COUNT(DISTINCT m.seriesName) FROM BookEntity b JOIN b.metadata m" String countQuery = "SELECT COUNT(DISTINCT m.seriesName) FROM BookEntity b JOIN b.metadata m"
+ (inProgressOnly ? " LEFT JOIN b.userBookProgress p ON p.user.id = :userId" : "") + (inProgressOnly ? " LEFT JOIN b.userBookProgress p ON p.user.id = :userId" : "")
+ " WHERE (b.deleted IS NULL OR b.deleted = false)" + " WHERE (b.deleted IS NULL OR b.deleted = false)"
+ " AND b.bookFiles IS NOT EMPTY" + " AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true)"
+ " AND m.seriesName IS NOT NULL" + " AND m.seriesName IS NOT NULL"
+ libraryClause + libraryClause
+ searchClause; + searchClause;
@@ -114,7 +114,7 @@ public class AppSeriesService {
+ "SELECT m.seriesName FROM BookEntity b JOIN b.metadata m" + "SELECT m.seriesName FROM BookEntity b JOIN b.metadata m"
+ " LEFT JOIN b.userBookProgress p ON p.user.id = :userId" + " LEFT JOIN b.userBookProgress p ON p.user.id = :userId"
+ " WHERE (b.deleted IS NULL OR b.deleted = false)" + " WHERE (b.deleted IS NULL OR b.deleted = false)"
+ " AND b.bookFiles IS NOT EMPTY" + " AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true)"
+ " AND m.seriesName IS NOT NULL" + " AND m.seriesName IS NOT NULL"
+ libraryClause + libraryClause
+ searchClause + searchClause
@@ -125,7 +125,7 @@ public class AppSeriesService {
String countAlt = "SELECT m.seriesName FROM BookEntity b JOIN b.metadata m" String countAlt = "SELECT m.seriesName FROM BookEntity b JOIN b.metadata m"
+ " LEFT JOIN b.userBookProgress p ON p.user.id = :userId" + " LEFT JOIN b.userBookProgress p ON p.user.id = :userId"
+ " WHERE (b.deleted IS NULL OR b.deleted = false)" + " WHERE (b.deleted IS NULL OR b.deleted = false)"
+ " AND b.bookFiles IS NOT EMPTY" + " AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true)"
+ " AND m.seriesName IS NOT NULL" + " AND m.seriesName IS NOT NULL"
+ libraryClause + libraryClause
+ searchClause + searchClause
@@ -178,7 +178,7 @@ public class AppSeriesService {
+ " JOIN FETCH b.metadata m" + " JOIN FETCH b.metadata m"
+ " WHERE m.seriesName IN :seriesNames" + " WHERE m.seriesName IN :seriesNames"
+ " AND (b.deleted IS NULL OR b.deleted = false)" + " AND (b.deleted IS NULL OR b.deleted = false)"
+ " AND b.bookFiles IS NOT EMPTY" + " AND (b.bookFiles IS NOT EMPTY OR b.isPhysical = true)"
+ libraryClause; + libraryClause;
var booksQ = entityManager.createQuery(booksQuery, BookEntity.class); var booksQ = entityManager.createQuery(booksQuery, BookEntity.class);
@@ -362,7 +362,7 @@ public class AppSeriesService {
private Specification<BookEntity> buildSeriesBooksSpec(Set<Long> accessibleLibraryIds, Long libraryId, String seriesName) { private Specification<BookEntity> buildSeriesBooksSpec(Set<Long> accessibleLibraryIds, Long libraryId, String seriesName) {
List<Specification<BookEntity>> specs = new ArrayList<>(); List<Specification<BookEntity>> specs = new ArrayList<>();
specs.add(AppBookSpecification.notDeleted()); specs.add(AppBookSpecification.notDeleted());
specs.add(AppBookSpecification.hasDigitalFile()); specs.add(AppBookSpecification.hasDigitalFileOrIsPhysical());
specs.add(AppBookSpecification.inSeries(seriesName)); specs.add(AppBookSpecification.inSeries(seriesName));
if (accessibleLibraryIds != null) { if (accessibleLibraryIds != null) {
@@ -202,6 +202,13 @@ public class AppBookSpecification {
return (root, query, cb) -> cb.isNotEmpty(root.get("bookFiles")); return (root, query, cb) -> cb.isNotEmpty(root.get("bookFiles"));
} }
public static Specification<BookEntity> hasDigitalFileOrIsPhysical() {
return (root, query, cb) -> cb.or(
cb.isNotEmpty(root.get("bookFiles")),
cb.equal(root.get("isPhysical"), true)
);
}
public static Specification<BookEntity> hasAudiobookFile() { public static Specification<BookEntity> hasAudiobookFile() {
return (root, query, cb) -> { return (root, query, cb) -> {
Subquery<Long> subquery = query.subquery(Long.class); Subquery<Long> subquery = query.subquery(Long.class);