refactor: track import progress per film instead of per batch
Replace batch-level progress (processedBatches/totalBatches) with film-level progress (processedFilms/totalFilms) for smoother UI updates. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -54,29 +54,27 @@ readonly class ImportFilmsBatchMessageHandler
|
||||
$movie = $this->filmImporter->importFromLtbxdMovie($ltbxdMovie);
|
||||
if (!$movie) {
|
||||
$this->importRepository->incrementFailedFilms($import);
|
||||
continue;
|
||||
} else {
|
||||
$this->actorSyncer->syncActorsForMovie($movie);
|
||||
|
||||
foreach ($movie->getActors() as $role) {
|
||||
$this->awardImporter->importForActor($role->getActor());
|
||||
}
|
||||
|
||||
$user = $this->em->getReference(\App\Entity\User::class, $userId);
|
||||
$existingLink = $this->em->getRepository(UserMovie::class)->findOneBy([
|
||||
'user' => $user,
|
||||
'movie' => $movie,
|
||||
]);
|
||||
if (!$existingLink) {
|
||||
$userMovie = new UserMovie();
|
||||
$userMovie->setUser($user);
|
||||
$userMovie->setMovie($movie);
|
||||
$this->em->persist($userMovie);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$this->actorSyncer->syncActorsForMovie($movie);
|
||||
|
||||
// Import awards for actors of this movie
|
||||
foreach ($movie->getActors() as $role) {
|
||||
$this->awardImporter->importForActor($role->getActor());
|
||||
}
|
||||
|
||||
$user = $this->em->getReference(\App\Entity\User::class, $userId);
|
||||
$existingLink = $this->em->getRepository(UserMovie::class)->findOneBy([
|
||||
'user' => $user,
|
||||
'movie' => $movie,
|
||||
]);
|
||||
if (!$existingLink) {
|
||||
$userMovie = new UserMovie();
|
||||
$userMovie->setUser($user);
|
||||
$userMovie->setMovie($movie);
|
||||
$this->em->persist($userMovie);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->warning('Failed to import film', [
|
||||
'film' => $ltbxdMovie->getName(),
|
||||
@@ -86,19 +84,16 @@ readonly class ImportFilmsBatchMessageHandler
|
||||
$this->importRepository->incrementFailedFilms($import);
|
||||
}
|
||||
|
||||
$processedFilms = $this->importRepository->incrementProcessedFilms($import);
|
||||
|
||||
$this->em->clear();
|
||||
$import = $this->em->getRepository(Import::class)->find($importId);
|
||||
}
|
||||
|
||||
$processedBatches = $this->importRepository->incrementProcessedBatches($import);
|
||||
|
||||
if ($processedBatches >= $import->getTotalBatches()) {
|
||||
// Refresh the entity to get updated failedFilms from DB
|
||||
$this->em->refresh($import);
|
||||
|
||||
$import->setStatus(Import::STATUS_COMPLETED);
|
||||
$import->setCompletedAt(new \DateTimeImmutable());
|
||||
$this->em->flush();
|
||||
if ($processedFilms >= $import->getTotalFilms()) {
|
||||
$import->setStatus(Import::STATUS_COMPLETED);
|
||||
$import->setCompletedAt(new \DateTimeImmutable());
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user