fix: handle multiple book files with the same checksum (#1724)

This commit is contained in:
James Ward
2026-06-12 08:27:01 -04:00
committed by GitHub
parent 798767c082
commit 0cc918f0ac
@@ -55,10 +55,10 @@ public interface BookRepository extends JpaRepository<BookEntity, Long>, JpaSpec
List<BookEntity> findAllForSummaryByIds(@Param("bookIds") Collection<Long> bookIds);
@EntityGraph(attributePaths = {"bookFiles", "metadata", "library", "libraryPath"})
@Query("SELECT b FROM BookEntity b JOIN b.bookFiles bf WHERE bf.currentHash = :currentHash AND bf.isBookFormat = true AND (b.deleted IS NULL OR b.deleted = false)")
@Query("SELECT b FROM BookEntity b JOIN b.bookFiles bf WHERE bf.currentHash = :currentHash AND bf.isBookFormat = true AND (b.deleted IS NULL OR b.deleted = false) ORDER BY b.id DESC LIMIT 1")
Optional<BookEntity> findByCurrentHash(@Param("currentHash") String currentHash);
@Query("SELECT b FROM BookEntity b JOIN FETCH b.bookFiles bf WHERE bf.currentHash = :currentHash AND bf.isBookFormat = true AND (b.deleted IS NULL OR b.deleted = false OR b.deletedAt > :cutoff)")
@Query("SELECT b FROM BookEntity b JOIN FETCH b.bookFiles bf WHERE bf.currentHash = :currentHash AND bf.isBookFormat = true AND (b.deleted IS NULL OR b.deleted = false OR b.deletedAt > :cutoff) ORDER BY b.id DESC LIMIT 1")
Optional<BookEntity> findByCurrentHashIncludingRecentlyDeleted(@Param("currentHash") String currentHash, @Param("cutoff") Instant cutoff);
Optional<BookEntity> findByBookCoverHash(String bookCoverHash);