fix(kobo): fix progress sync graph error (#858)

This commit is contained in:
Alex
2026-04-25 14:31:45 +01:00
committed by GitHub
parent bdd54a4565
commit 59fcfb1689
7 changed files with 167 additions and 7 deletions
@@ -15,6 +15,7 @@ import java.util.Optional;
@Repository
public interface UserBookFileProgressRepository extends JpaRepository<UserBookFileProgressEntity, Long> {
@EntityGraph(attributePaths = {"bookFile", "bookFile.book", "bookFile.book.libraryPath", "bookFile.book.library"})
Optional<UserBookFileProgressEntity> findByUserIdAndBookFileId(Long userId, Long bookFileId);
@Query("""
@@ -52,7 +53,7 @@ public interface UserBookFileProgressRepository extends JpaRepository<UserBookFi
@Param("bookId") Long bookId
);
@EntityGraph(attributePaths = {"bookFile", "bookFile.book"})
@EntityGraph(attributePaths = {"bookFile", "bookFile.book", "bookFile.book.libraryPath", "bookFile.book.library"})
@Query("""
SELECT ubfp FROM UserBookFileProgressEntity ubfp
WHERE ubfp.user.id = :userId
@@ -63,7 +64,7 @@ public interface UserBookFileProgressRepository extends JpaRepository<UserBookFi
@Param("bookIds") Iterable<Long> bookIds
);
@EntityGraph(attributePaths = {"bookFile", "bookFile.book"})
@EntityGraph(attributePaths = {"bookFile", "bookFile.book", "bookFile.book.libraryPath", "bookFile.book.library"})
@Query("""
SELECT ubfp FROM UserBookFileProgressEntity ubfp
WHERE ubfp.user.id = :userId
@@ -7,6 +7,7 @@ import org.booklore.model.dto.RatingDistributionDto;
import org.booklore.model.dto.StatusDistributionDto;
import org.booklore.model.entity.UserBookProgressEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@@ -25,10 +26,22 @@ public interface UserBookProgressRepository extends JpaRepository<UserBookProgre
Optional<UserBookProgressEntity> findByUserIdAndBookId(Long userId, Long bookId);
@EntityGraph(attributePaths = {"book", "book.bookFiles", "book.library", "book.libraryPath"})
@Query("""
SELECT DISTINCT ubp FROM UserBookProgressEntity ubp
WHERE ubp.user.id = :userId
AND ubp.book.id = :bookId
""")
Optional<UserBookProgressEntity> findByUserIdAndBookIdForKoboSync(
@Param("userId") Long userId,
@Param("bookId") Long bookId
);
List<UserBookProgressEntity> findByUserIdAndBookIdIn(Long userId, Set<Long> bookIds);
@EntityGraph(attributePaths = {"book", "book.bookFiles", "book.library", "book.libraryPath"})
@Query("""
SELECT ubp FROM UserBookProgressEntity ubp
SELECT DISTINCT ubp FROM UserBookProgressEntity ubp
WHERE ubp.user.id = :userId
AND ubp.book.id IN (
SELECT ksb.bookId FROM KoboSnapshotBookEntity ksb
@@ -256,7 +256,7 @@ public class KoboEntitlementService {
.orElse(null);
Optional<UserBookProgressEntity> userProgress = progressRepository
.findByUserIdAndBookId(userId, book.getId());
.findByUserIdAndBookIdForKoboSync(userId, book.getId());
UserBookFileProgressEntity fileProgress = findSyncedEpubFileProgress(userId, book).orElse(null);
boolean twoWaySync = koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync();
@@ -156,7 +156,7 @@ public class KoboReadingStateService {
try {
Long bookId = Long.parseLong(entitlementId);
UserBookFileProgressEntity fileProgress = findSyncedEpubFileProgress(userId, bookId).orElse(null);
progressRepository.findByUserIdAndBookId(userId, bookId)
progressRepository.findByUserIdAndBookIdForKoboSync(userId, bookId)
.filter(readingStateBuilder::shouldUseWebReaderProgress)
.ifPresent(progress -> state.setCurrentBookmark(
readingStateBuilder.buildBookmarkFromProgress(progress, fileProgress)));
@@ -171,7 +171,7 @@ public class KoboReadingStateService {
BookLoreUser user = authenticationService.getAuthenticatedUser();
boolean twoWaySync = koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync();
return progressRepository.findByUserIdAndBookId(user.getId(), bookId)
return progressRepository.findByUserIdAndBookIdForKoboSync(user.getId(), bookId)
.filter(progress -> progress.getKoboProgressPercent() != null || progress.getKoboLocation() != null || (twoWaySync && progress.getEpubProgressPercent() != null))
.map(progress -> readingStateBuilder.buildReadingStateFromProgress(
entitlementId,
@@ -311,7 +311,7 @@ public class KoboReadingStateService {
}
private Optional<UserBookFileProgressEntity> findSyncedEpubFileProgress(Long userId, Long bookId) {
return bookRepository.findById(bookId)
return bookRepository.findByIdWithBookFiles(bookId)
.flatMap(book -> findSyncedEpubFileProgress(userId, book));
}