Optimize memory usage for batch processing of template images
NewsletterTemplateEntity carries base64 data of image. This commit changes how we load templates entities when we process thumbnail images so that there is only one template in memory. [MAILPOET-2686]
This commit is contained in:
committed by
Veljko V
parent
ab23b06ff8
commit
5134713c2d
@@ -103,6 +103,13 @@ abstract class Repository {
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param T $entity
|
||||
*/
|
||||
public function detach($entity) {
|
||||
$this->entityManager->detach($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<T>
|
||||
*/
|
||||
|
@@ -98,4 +98,14 @@ class NewsletterTemplatesRepository extends Repository {
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function getIdsOfEditableTemplates(): array {
|
||||
$result = $this->doctrineRepository->createQueryBuilder('nt')
|
||||
->select('nt.id')
|
||||
->where('nt.readonly = :readonly')
|
||||
->setParameter('readonly', false)
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
return array_column($result, 'id');
|
||||
}
|
||||
}
|
||||
|
@@ -34,9 +34,14 @@ class ThumbnailSaver {
|
||||
}
|
||||
|
||||
public function ensureTemplateThumbnailsForAll() {
|
||||
$templates = $this->repository->findBy(['readonly' => false]);
|
||||
foreach ($templates as $template) {
|
||||
$templateIds = $this->repository->getIdsOfEditableTemplates();
|
||||
foreach ($templateIds as $templateId) {
|
||||
$template = $this->repository->findOneById((int)$templateId);
|
||||
if (!$template) continue;
|
||||
$this->ensureTemplateThumbnailFile($template);
|
||||
// Remove template entity from memory after it was processed
|
||||
$this->repository->detach($template);
|
||||
unset($template);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user