chore(api): drop unused LibraryScanListener (#2434)

This commit is contained in:
James Ward
2026-08-31 20:05:01 -04:00
committed by GitHub
parent a88982bb78
commit e0c8118312
4 changed files with 2 additions and 84 deletions
@@ -1,62 +0,0 @@
package org.booklore.service.library;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;
import org.booklore.task.options.RescanLibraryContext;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* Handles library scan requests after the triggering transaction commits.
* Scans are executed asynchronously with deduplication to prevent concurrent scans.
* Security context is automatically propagated via DelegatingSecurityContextExecutor.
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class LibraryScanListener {
private final LibraryProcessingService libraryProcessingService;
private final Set<Long> scanningLibraries = ConcurrentHashMap.newKeySet();
public boolean isScanning(long libraryId) {
return scanningLibraries.contains(libraryId);
}
@Async("taskExecutor")
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true)
public void handle(LibraryScanRequestedEvent event) {
long libraryId = event.libraryId();
if (!scanningLibraries.add(libraryId)) {
log.warn("Library {} is already being scanned, skipping duplicate request", libraryId);
return;
}
try {
log.info("Starting background scan for library ID {} (full rescan: {})", libraryId, event.fullRescan());
if (event.fullRescan()) {
libraryProcessingService.rescanLibrary(RescanLibraryContext.builder().libraryId(libraryId).build());
} else {
libraryProcessingService.processLibrary(libraryId);
}
log.info("Completed background scan for library ID {}", libraryId);
} catch (InvalidDataAccessApiUsageException e) {
log.debug("InvalidDataAccessApiUsageException during library scan - Library id: {}", libraryId, e);
} catch (IOException e) {
log.error("IO error during library scan for library ID {}: {}", libraryId, e.getMessage(), e);
} catch (Exception e) {
log.error("Unexpected error during library scan for library ID {}: {}", libraryId, e.getMessage(), e);
} finally {
scanningLibraries.remove(libraryId);
}
}
}
@@ -1,10 +0,0 @@
package org.booklore.service.library;
/**
* Event published when a library scan is requested.
* The actual scan will be performed after the current transaction commits.
*
* @param libraryId the ID of the library to scan
*/
public record LibraryScanRequestedEvent(long libraryId, boolean fullRescan) {
}
@@ -12,7 +12,6 @@ import org.booklore.repository.BookRepository;
import org.booklore.repository.LibraryRepository;
import org.booklore.service.file.FileFingerprint;
import org.booklore.service.library.LibraryProcessingService;
import org.booklore.service.library.LibraryScanListener;
import org.booklore.util.FileUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -46,7 +45,6 @@ public class LibraryFileEventProcessor implements SmartLifecycle {
private final BookFileTransactionalHandler bookFileTransactionalHandler;
private final BookFilePersistenceService bookFilePersistenceService;
private final LibraryProcessingService libraryProcessingService;
private final LibraryScanListener libraryScanListener;
private final PendingDeletionPool pendingDeletionPool;
private ScheduledExecutorService scheduler;
@@ -106,11 +104,6 @@ public class LibraryFileEventProcessor implements SmartLifecycle {
}
public void processEvent(WatchEvent.Kind<?> eventKind, long libraryId, Path fullPath, boolean isDirectory) {
if (libraryScanListener.isScanning(libraryId)) {
log.debug("[SKIP] Library {} is currently being scanned, ignoring file event for '{}'", libraryId, fullPath);
return;
}
Path path = fullPath.toAbsolutePath().normalize();
if (eventKind == StandardWatchEventKinds.ENTRY_DELETE) {