fix(opds): ensure consistent sort by adding book ID as tie breaker (#2708)
This commit is contained in:
@@ -21,7 +21,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
// ALL BOOKS - Two Query Pattern
|
||||
// ============================================
|
||||
|
||||
@Query("SELECT b.id FROM BookEntity b WHERE (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC")
|
||||
@Query("SELECT b.id FROM BookEntity b WHERE (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC, b.id DESC")
|
||||
Page<Long> findBookIds(Pageable pageable);
|
||||
|
||||
@EntityGraph(attributePaths = {"metadata", "bookFiles", "shelves"})
|
||||
@@ -32,7 +32,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
// RECENT BOOKS - Two Query Pattern
|
||||
// ============================================
|
||||
|
||||
@Query("SELECT b.id FROM BookEntity b WHERE (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC")
|
||||
@Query("SELECT b.id FROM BookEntity b WHERE (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC, b.id DESC")
|
||||
Page<Long> findRecentBookIds(Pageable pageable);
|
||||
|
||||
// Uses same findAllWithMetadataByIds for second query
|
||||
@@ -41,7 +41,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
// BOOKS BY LIBRARY IDs - Two Query Pattern
|
||||
// ============================================
|
||||
|
||||
@Query("SELECT b.id FROM BookEntity b WHERE b.library.id IN :libraryIds AND (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC")
|
||||
@Query("SELECT b.id FROM BookEntity b WHERE b.library.id IN :libraryIds AND (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC, b.id DESC")
|
||||
Page<Long> findBookIdsByLibraryIds(@Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
||||
|
||||
@EntityGraph(attributePaths = {"metadata", "bookFiles", "shelves"})
|
||||
@@ -52,7 +52,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
// RECENT BOOKS BY LIBRARY IDs - Two Query Pattern
|
||||
// ============================================
|
||||
|
||||
@Query("SELECT b.id FROM BookEntity b WHERE b.library.id IN :libraryIds AND (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC")
|
||||
@Query("SELECT b.id FROM BookEntity b WHERE b.library.id IN :libraryIds AND (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC, b.id DESC")
|
||||
Page<Long> findRecentBookIdsByLibraryIds(@Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
||||
|
||||
// Uses findAllWithMetadataByIdsAndLibraryIds for second query
|
||||
@@ -61,7 +61,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
// BOOKS BY SHELF ID - Two Query Pattern
|
||||
// ============================================
|
||||
|
||||
@Query("SELECT DISTINCT b.id FROM BookEntity b JOIN b.shelves s WHERE s.id = :shelfId AND (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC")
|
||||
@Query("SELECT DISTINCT b.id FROM BookEntity b JOIN b.shelves s WHERE s.id = :shelfId AND (b.deleted IS NULL OR b.deleted = false) ORDER BY b.addedOn DESC, b.id DESC")
|
||||
Page<Long> findBookIdsByShelfId(@Param("shelfId") Long shelfId, Pageable pageable);
|
||||
|
||||
@EntityGraph(attributePaths = {"metadata", "bookFiles", "shelves"})
|
||||
@@ -78,7 +78,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
WHERE (b.deleted IS NULL OR b.deleted = false) AND (
|
||||
m.searchText LIKE CONCAT('%', :text, '%')
|
||||
)
|
||||
ORDER BY b.addedOn DESC
|
||||
ORDER BY b.addedOn DESC, b.id DESC
|
||||
""")
|
||||
Page<Long> findBookIdsByMetadataSearch(@Param("text") String text, Pageable pageable);
|
||||
|
||||
@@ -98,7 +98,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
AND (
|
||||
m.searchText LIKE CONCAT('%', :text, '%')
|
||||
)
|
||||
ORDER BY b.addedOn DESC
|
||||
ORDER BY b.addedOn DESC, b.id DESC
|
||||
""")
|
||||
Page<Long> findBookIdsByMetadataSearchAndLibraryIds(@Param("text") String text, @Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
||||
|
||||
@@ -120,7 +120,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
AND (
|
||||
m.searchText LIKE CONCAT('%', :text, '%')
|
||||
)
|
||||
ORDER BY b.addedOn DESC
|
||||
ORDER BY b.addedOn DESC, b.id DESC
|
||||
""")
|
||||
Page<Long> findBookIdsByMetadataSearchAndShelfIds(@Param("text") String text, @Param("libraryIds") Collection<Long> libraryIds, @Param("shelfIds") Collection<Long> shelfIds, Pageable pageable);
|
||||
|
||||
@@ -147,7 +147,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
b.library.id IN :libraryIds
|
||||
AND s.id IN :shelfIds
|
||||
AND (b.deleted IS NULL OR b.deleted = false)
|
||||
ORDER BY b.addedOn DESC
|
||||
ORDER BY b.addedOn DESC, b.id DESC
|
||||
""")
|
||||
Page<Long> findBookIdsByShelfIds(@Param("libraryIds") Collection<Long> libraryIds, @Param("shelfIds") Collection<Long> shelfIds, Pageable pageable);
|
||||
|
||||
@@ -181,7 +181,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
JOIN m.book b
|
||||
WHERE (b.deleted IS NULL OR b.deleted = false)
|
||||
AND a.name IS NOT NULL
|
||||
ORDER BY a.name
|
||||
ORDER BY a.name, b.id DESC
|
||||
""")
|
||||
Page<String> findDistinctAuthorNames(Pageable pageable);
|
||||
|
||||
@@ -193,7 +193,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
WHERE (b.deleted IS NULL OR b.deleted = false)
|
||||
AND b.library.id IN :libraryIds
|
||||
AND a.name IS NOT NULL
|
||||
ORDER BY a.name
|
||||
ORDER BY a.name, b.id DESC
|
||||
""")
|
||||
Page<String> findDistinctAuthorNamesByLibraryIds(@Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
||||
|
||||
@@ -207,7 +207,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
JOIN m.authors a
|
||||
WHERE a.name = :authorName
|
||||
AND (b.deleted IS NULL OR b.deleted = false)
|
||||
ORDER BY b.addedOn DESC
|
||||
ORDER BY b.addedOn DESC, b.id DESC
|
||||
""")
|
||||
Page<Long> findBookIdsByAuthorName(@Param("authorName") String authorName, Pageable pageable);
|
||||
|
||||
@@ -218,7 +218,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
WHERE a.name = :authorName
|
||||
AND b.library.id IN :libraryIds
|
||||
AND (b.deleted IS NULL OR b.deleted = false)
|
||||
ORDER BY b.addedOn DESC
|
||||
ORDER BY b.addedOn DESC, b.id DESC
|
||||
""")
|
||||
Page<Long> findBookIdsByAuthorNameAndLibraryIds(@Param("authorName") String authorName, @Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
||||
|
||||
@@ -232,7 +232,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
WHERE (b.deleted IS NULL OR b.deleted = false)
|
||||
AND m.seriesName IS NOT NULL
|
||||
AND m.seriesName != ''
|
||||
ORDER BY m.seriesName
|
||||
ORDER BY m.seriesName, m.bookId
|
||||
""")
|
||||
Page<String> findDistinctSeries(Pageable pageable);
|
||||
|
||||
@@ -243,7 +243,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
AND b.library.id IN :libraryIds
|
||||
AND m.seriesName IS NOT NULL
|
||||
AND m.seriesName != ''
|
||||
ORDER BY m.seriesName
|
||||
ORDER BY m.seriesName, m.bookId
|
||||
""")
|
||||
Page<String> findDistinctSeriesByLibraryIds(@Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
||||
|
||||
@@ -256,7 +256,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
JOIN b.metadata m
|
||||
WHERE m.seriesName = :seriesName
|
||||
AND (b.deleted IS NULL OR b.deleted = false)
|
||||
ORDER BY COALESCE(m.seriesNumber, 999999), b.addedOn DESC
|
||||
ORDER BY COALESCE(m.seriesNumber, 999999), b.addedOn DESC, b.id DESC
|
||||
""")
|
||||
Page<Long> findBookIdsBySeriesName(@Param("seriesName") String seriesName, Pageable pageable);
|
||||
|
||||
@@ -266,7 +266,7 @@ public interface BookOpdsRepository extends JpaRepository<BookEntity, Long>, Jpa
|
||||
WHERE m.seriesName = :seriesName
|
||||
AND b.library.id IN :libraryIds
|
||||
AND (b.deleted IS NULL OR b.deleted = false)
|
||||
ORDER BY COALESCE(m.seriesNumber, 999999), b.addedOn DESC
|
||||
ORDER BY COALESCE(m.seriesNumber, 999999), b.addedOn DESC, b.id DESC
|
||||
""")
|
||||
Page<Long> findBookIdsBySeriesNameAndLibraryIds(@Param("seriesName") String seriesName, @Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
||||
}
|
||||
Reference in New Issue
Block a user