From 525d9dac7cbd759adc93d735e781693cb97a38a1 Mon Sep 17 00:00:00 2001 From: Michael Onken Date: Tue, 14 May 2024 12:31:15 +0200 Subject: [PATCH 1/6] Collect garbage after executing a fixture --- src/EventListener/PimcoreLoadOptimization.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/EventListener/PimcoreLoadOptimization.php b/src/EventListener/PimcoreLoadOptimization.php index 609bc72..ad85580 100644 --- a/src/EventListener/PimcoreLoadOptimization.php +++ b/src/EventListener/PimcoreLoadOptimization.php @@ -3,6 +3,7 @@ namespace Neusta\Pimcore\FixtureBundle\EventListener; use Doctrine\DBAL\Logging\SQLLogger; +use Neusta\Pimcore\FixtureBundle\Event\AfterExecuteFixture; use Neusta\Pimcore\FixtureBundle\Event\AfterLoadFixtures; use Neusta\Pimcore\FixtureBundle\Event\BeforeLoadFixtures; use Pimcore\Cache; @@ -29,6 +30,7 @@ public static function getSubscribedEvents(): array return [ BeforeLoadFixtures::class => 'beforeCommand', AfterLoadFixtures::class => 'afterCommand', + AfterExecuteFixture::class => 'afterExecute', ]; } @@ -52,4 +54,9 @@ public function afterCommand(): void $this->versionEnabled && Version::enable(); $this->cacheEnabled && Cache::enable(); } + + public function afterExecute(): void + { + \Pimcore::collectGarbage(); + } } From c054e133c98893ed8c15ab380788d271230ebd2f Mon Sep 17 00:00:00 2001 From: Michael Onken Date: Tue, 14 May 2024 14:02:24 +0200 Subject: [PATCH 2/6] Mention console commands in README --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index cadae5c..9b9d7b4 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,14 @@ final class MyCustomTest extends BaseKernelTestCase } ``` +To load fixtures in your local environment or as part of a deployment two commands are provided: +- `neusta:pimcore-fixture:load` (Loads a defined fixture class.) +- `neusta:pimcore-fixtures:load` (Loads all defined fixture classes.) + +Beware that loading a large amount of objects may lead to a high consumption of memory. +Should you encounter memory issues when running the commands in `dev` environments you may want to try +setting the environment to `prod`. This appears to be beneficial in terms of pimcore's memory consumption. + ### Accessing Services from the Fixtures As the Fixtures are just normal PHP Services you can use all DI features like constructor, setter or property injection as usual. From f3d5ca868730effed2d29719f601472babb676da Mon Sep 17 00:00:00 2001 From: Michael Onken Date: Tue, 14 May 2024 15:27:09 +0200 Subject: [PATCH 3/6] Mention helpful console command options in README --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b9d7b4..7d15b22 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,13 @@ To load fixtures in your local environment or as part of a deployment two comman Beware that loading a large amount of objects may lead to a high consumption of memory. Should you encounter memory issues when running the commands in `dev` environments you may want to try -setting the environment to `prod`. This appears to be beneficial in terms of pimcore's memory consumption. +setting the environment to `prod`. Disabling the debug mode also seems to be beneficial in terms of memory consumption. + +For example provide these options when using the symfony console: +``` +console --env=prod --no-debug neusta:pimcore-fixtures:load +``` + ### Accessing Services from the Fixtures From 4226a28af9e8ebecfdb2d196e1374a46913a6e22 Mon Sep 17 00:00:00 2001 From: m0nken Date: Tue, 14 May 2024 15:32:58 +0200 Subject: [PATCH 4/6] Update README.md Co-authored-by: Jacob Dreesen --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7d15b22..07fa278 100644 --- a/README.md +++ b/README.md @@ -187,9 +187,8 @@ Should you encounter memory issues when running the commands in `dev` environmen setting the environment to `prod`. Disabling the debug mode also seems to be beneficial in terms of memory consumption. For example provide these options when using the symfony console: -``` -console --env=prod --no-debug neusta:pimcore-fixtures:load -``` +```shell +bin/console --env=prod --no-debug neusta:pimcore-fixtures:load ### Accessing Services from the Fixtures From 6623bbd47fbeeeefcf87015d7b079c737ec8d494 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Tue, 14 May 2024 15:41:37 +0200 Subject: [PATCH 5/6] Fix code block in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07fa278..7ef48b7 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ setting the environment to `prod`. Disabling the debug mode also seems to be ben For example provide these options when using the symfony console: ```shell bin/console --env=prod --no-debug neusta:pimcore-fixtures:load - +``` ### Accessing Services from the Fixtures From 7a2131be178c0b49b8b90b152954bb8d2f461a49 Mon Sep 17 00:00:00 2001 From: Michael Onken Date: Tue, 14 May 2024 16:32:35 +0200 Subject: [PATCH 6/6] Revert collectGarbage() as it does not really provide a benefit --- src/EventListener/PimcoreLoadOptimization.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/EventListener/PimcoreLoadOptimization.php b/src/EventListener/PimcoreLoadOptimization.php index ad85580..609bc72 100644 --- a/src/EventListener/PimcoreLoadOptimization.php +++ b/src/EventListener/PimcoreLoadOptimization.php @@ -3,7 +3,6 @@ namespace Neusta\Pimcore\FixtureBundle\EventListener; use Doctrine\DBAL\Logging\SQLLogger; -use Neusta\Pimcore\FixtureBundle\Event\AfterExecuteFixture; use Neusta\Pimcore\FixtureBundle\Event\AfterLoadFixtures; use Neusta\Pimcore\FixtureBundle\Event\BeforeLoadFixtures; use Pimcore\Cache; @@ -30,7 +29,6 @@ public static function getSubscribedEvents(): array return [ BeforeLoadFixtures::class => 'beforeCommand', AfterLoadFixtures::class => 'afterCommand', - AfterExecuteFixture::class => 'afterExecute', ]; } @@ -54,9 +52,4 @@ public function afterCommand(): void $this->versionEnabled && Version::enable(); $this->cacheEnabled && Cache::enable(); } - - public function afterExecute(): void - { - \Pimcore::collectGarbage(); - } }