Fix event handling

This commit is contained in:
aditya.chandel
2025-05-23 23:43:02 -06:00
parent ff64362edb
commit 93f15720fe
@@ -159,8 +159,14 @@ public class LibraryProcessingService {
LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId)); LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
notificationService.sendMessage(Topic.LOG, createLogNotification("Started refreshing library: " + libraryEntity.getName())); notificationService.sendMessage(Topic.LOG, createLogNotification("Started refreshing library: " + libraryEntity.getName()));
detectMovedBooksAndUpdatePaths(libraryEntity); detectMovedBooksAndUpdatePaths(libraryEntity);
entityManager.flush();
entityManager.clear();
deleteRemovedBooks(detectDeletedBookIds(libraryEntity)); deleteRemovedBooks(detectDeletedBookIds(libraryEntity));
entityManager.flush();
entityManager.clear();
processLibraryFiles(detectNewBookPaths(libraryEntity)); processLibraryFiles(detectNewBookPaths(libraryEntity));
entityManager.flush();
entityManager.clear();
notificationService.sendMessage(Topic.LOG, createLogNotification("Finished refreshing library: " + libraryEntity.getName())); notificationService.sendMessage(Topic.LOG, createLogNotification("Finished refreshing library: " + libraryEntity.getName()));
} }
@@ -207,7 +213,9 @@ public class LibraryProcessingService {
protected void deleteRemovedBooks(List<Long> bookIds) { protected void deleteRemovedBooks(List<Long> bookIds) {
bookRepository.deleteByIdIn(bookIds); bookRepository.deleteByIdIn(bookIds);
notificationService.sendMessage(Topic.BOOKS_REMOVE, bookIds); notificationService.sendMessage(Topic.BOOKS_REMOVE, bookIds);
log.info("Books removed: {}", bookIds); if (bookIds.size() > 1) {
log.info("Books removed: {}", bookIds);
}
} }
@Transactional @Transactional