Skip to content

Commit

Permalink
feat: Flush email to DB only if there are no other pending changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LuigiCardamone committed Feb 25, 2019
1 parent 6ed8f67 commit cda6703
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Entity/EmailRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,20 @@ public function addEmail(Email $email)
$email->setStatus(Email::STATUS_READY);
$email->setRetries(0);
$email->setCreatedAt(new \DateTime());

$scheduledDbChanges = 0;
$scheduledDbChanges += count($em->getUnitOfWork()->getScheduledEntityInsertions());
$scheduledDbChanges += count($em->getUnitOfWork()->getScheduledEntityUpdates());
$scheduledDbChanges += count($em->getUnitOfWork()->getScheduledEntityDeletions());
$scheduledDbChanges += count($em->getUnitOfWork()->getScheduledCollectionUpdates());
$scheduledDbChanges += count($em->getUnitOfWork()->getScheduledCollectionUpdates());

$em->persist($email);
$em->flush();

// Flush only if there are not other db changes
if ($scheduledDbChanges === 0) {
$em->flush();
}
}

public function getAllEmails($limit = null, $offset = null)
Expand Down

0 comments on commit cda6703

Please sign in to comment.