Cleaner fix to the duplication issue with batch processing.

This commit is contained in:
Buster "Silver Eagle" Neece 2020-01-30 19:16:37 -06:00
parent d28104c686
commit d00d14d329
No known key found for this signature in database
GPG key ID: 6D9E12FF03411F4E
3 changed files with 17 additions and 5 deletions

View file

@ -5,6 +5,7 @@ use App\Entity;
use App\MessageQueue;
use App\Radio\Filesystem;
use Doctrine\ORM\EntityManager;
use DoctrineBatchUtils\BatchProcessing\SimpleBatchIteratorAggregate;
use Psr\Log\LoggerInterface;
class FolderPlaylists extends AbstractTask
@ -39,9 +40,14 @@ class FolderPlaylists extends AbstractTask
*/
public function run($force = false): void
{
$stations = $this->em->getRepository(Entity\Station::class)->findAll();
$stations = SimpleBatchIteratorAggregate::fromQuery(
$this->em->createQuery(/** @lang DQL */ 'SELECT s FROM App\Entity\Station s'),
1
);
foreach ($stations as $station) {
/** @var Entity\Station $station */
$this->logger->info('Processing auto-assigning folders for station...', [
'station' => $station->getName(),
]);

View file

@ -76,11 +76,13 @@ class Media extends AbstractTask
*/
public function run($force = false): void
{
$stations = $this->em->getRepository(Entity\Station::class)->findAll();
$stations = SimpleBatchIteratorAggregate::fromQuery(
$this->em->createQuery(/** @lang DQL */ 'SELECT s FROM App\Entity\Station s'),
1
);
foreach ($stations as $station) {
$station = $this->em->find(Entity\Station::class, $station->getId());
/** @var Entity\Station $station */
$this->logger->info('Processing media for station...', [
'station' => $station->getName(),
]);

View file

@ -38,7 +38,11 @@ class RadioAutomation extends AbstractTask
public function run($force = false): void
{
// Check all stations for automation settings.
$stations = $this->em->getRepository(Entity\Station::class)->findAll();
// Use this to avoid detached entity errors.
$stations = SimpleBatchIteratorAggregate::fromQuery(
$this->em->createQuery(/** @lang DQL */ 'SELECT s FROM App\Entity\Station s'),
1
);
foreach ($stations as $station) {
/** @var Entity\Station $station */