refactor: embed film data directly in batch messages

Avoid re-parsing the entire CSV file in each batch handler by including
the film data in the message payload itself.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
thibaud-leclere
2026-04-01 19:25:45 +02:00
parent 087b063f1f
commit 8c73a22eff
3 changed files with 24 additions and 20 deletions

View File

@@ -6,14 +6,13 @@ namespace App\MessageHandler;
use App\Entity\Import;
use App\Entity\UserMovie;
use App\Gateway\LtbxdGateway;
use App\Message\ImportFilmsBatchMessage;
use App\Model\Ltbxd\LtbxdMovie;
use App\Repository\ImportRepository;
use App\Import\ActorSyncer;
use App\Import\AwardImporter;
use App\Import\FilmImporter;
use Doctrine\ORM\EntityManagerInterface;
use League\Flysystem\FilesystemOperator;
use Psr\Log\LoggerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
@@ -22,8 +21,6 @@ readonly class ImportFilmsBatchMessageHandler
{
public function __construct(
private EntityManagerInterface $em,
private FilesystemOperator $defaultStorage,
private LtbxdGateway $ltbxdGateway,
private FilmImporter $filmImporter,
private ActorSyncer $actorSyncer,
private ImportRepository $importRepository,
@@ -40,17 +37,15 @@ readonly class ImportFilmsBatchMessageHandler
return;
}
$csvContent = $this->defaultStorage->read($import->getFilePath());
$tmpFile = tempnam(sys_get_temp_dir(), 'import_');
file_put_contents($tmpFile, $csvContent);
try {
$ltbxdMovies = $this->ltbxdGateway->parseFileFromPath($tmpFile);
} finally {
unlink($tmpFile);
}
$batch = array_slice($ltbxdMovies, $message->offset, $message->limit);
$batch = array_map(
fn (array $film) => new LtbxdMovie(
date: new \DateTime($film['date']),
name: $film['name'],
year: $film['year'],
ltbxdUri: $film['ltbxdUri'],
),
$message->films,
);
$userId = $import->getUser()->getId();
$importId = $import->getId();