fix(bookdrop): fix 'Select All' query logic and improve filename fallback for missing metadata (#1828)

* fix(bookdrop): fix 'Select All' query logic and improve filename fallback for missing metadata

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* fix(tests): update BookDropServiceTest and PathPatternResolverTest to use findAllIds method

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

---------

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
Balázs Szücs
2025-12-12 08:32:57 -07:00
committed by GitHub
parent 1a7d92c60d
commit 62ea319536
7 changed files with 108 additions and 9 deletions
@@ -31,5 +31,8 @@ public interface BookdropFileRepository extends JpaRepository<BookdropFileEntity
@Query("SELECT f.id FROM BookdropFileEntity f WHERE f.id NOT IN :excludedIds")
List<Long> findAllExcludingIdsFlat(@Param("excludedIds") List<Long> excludedIds);
@Query("SELECT f.id FROM BookdropFileEntity f")
List<Long> findAllIds();
}
@@ -186,7 +186,12 @@ public class BookDropService {
AtomicInteger failedCount,
AtomicInteger totalFilesProcessed) {
List<Long> excludedIds = Optional.ofNullable(request.getExcludedIds()).orElse(List.of());
List<Long> allIds = bookdropFileRepository.findAllExcludingIdsFlat(excludedIds);
List<Long> allIds;
if (excludedIds.isEmpty()) {
allIds = bookdropFileRepository.findAllIds();
} else {
allIds = bookdropFileRepository.findAllExcludingIdsFlat(excludedIds);
}
log.info("SelectAll: Total files to finalize (after exclusions): {}, Excluded IDs: {}", allIds.size(), excludedIds);
processFileChunks(allIds, metadataById, defaultLibraryId, defaultPathId, results, failedCount, totalFilesProcessed);
@@ -55,9 +55,19 @@ public class PathPatternResolver {
return filename;
}
String filenameBase = "Untitled";
if (filename != null && !filename.isBlank()) {
int lastDot = filename.lastIndexOf('.');
if (lastDot > 0) {
filenameBase = filename.substring(0, lastDot);
} else {
filenameBase = filename;
}
}
String title = sanitize(metadata != null && metadata.getTitle() != null
? metadata.getTitle()
: "Untitled");
: filenameBase);
String subtitle = sanitize(metadata != null ? metadata.getSubtitle() : "");