1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-29 10:10:25 -07:00

Fix loader memory leaks

This commit is contained in:
Unknown 2017-06-08 18:00:36 +02:00
parent 80bea7f0c9
commit 11f1d9eec1
3 changed files with 16 additions and 3 deletions

View File

@ -12,6 +12,9 @@ class BricksetManager
*/ */
private $bricksetClient; private $bricksetClient;
/**
* @var CacheProvider
*/
private $cache; private $cache;
const CACHE_LIFETIME = 86400; const CACHE_LIFETIME = 86400;

View File

@ -162,25 +162,33 @@ class ModelLoader extends BaseLoader
$files = $this->ldrawLibraryContext->listContents('parts', false); $files = $this->ldrawLibraryContext->listContents('parts', false);
$this->initProgressBar(count($files)); $this->initProgressBar(count($files));
$index = 0;
$connection = $this->em->getConnection();
$connection->getConfiguration()->setSQLLogger(null);
foreach ($files as $file) { foreach ($files as $file) {
$this->progressBar->setMessage($file['basename']); $this->progressBar->setMessage($file['basename']);
if ($file['type'] == 'file' && $file['extension'] == 'dat') { if ($file['type'] == 'file' && $file['extension'] == 'dat') {
$connection = $this->em->getConnection();
$connection->beginTransaction(); $connection->beginTransaction();
try { try {
$this->loadModel($this->ldrawLibraryContext->getAdapter()->getPathPrefix().$file['path']); $this->loadModel($this->ldrawLibraryContext->getAdapter()->getPathPrefix().$file['path']);
// clear managed objects to avoid memory issues
if($index++ % 50 == 0) {
$this->em->clear();
}
$connection->commit(); $connection->commit();
} catch (\Exception $exception) { } catch (\Exception $exception) {
$connection->rollBack(); $connection->rollBack();
$this->logger->error($exception->getMessage()); $this->logger->error($exception->getMessage());
} }
$connection->close();
} }
$this->progressBar->advance(); $this->progressBar->advance();
} }
$connection->close();
$this->progressBar->finish(); $this->progressBar->finish();
} }

View File

@ -152,6 +152,8 @@ class StlRendererService
throw new ConvertingFailedException($file, 'POV'); throw new ConvertingFailedException($file, 'POV');
} }
unset($incFile);
return $outputFile; return $outputFile;
} }