@@ -25,12 +25,39 @@ public function __construct(SalesChannelRepository $productRepository, array $cu
2525
2626 public function getByContext (SalesChannelContext $ context , int $ batchSize = 100 ): iterable
2727 {
28- $ criteria = $ this ->getCriteria ($ batchSize );
29- $ products = $ this ->productRepository ->search ($ criteria , $ context );
30- while ($ products ->count ()) {
31- yield from $ products ;
32- $ criteria ->setOffset ($ criteria ->getOffset () + $ criteria ->getLimit ());
28+ $ offset = 0 ;
29+
30+ while (true ) {
31+ $ criteria = $ this ->getCriteria ($ batchSize , $ offset );
3332 $ products = $ this ->productRepository ->search ($ criteria , $ context );
33+
34+ if ($ products ->count () === 0 ) {
35+ break ;
36+ }
37+
38+ foreach ($ products ->getElements () as $ product ) {
39+ yield $ product ;
40+ }
41+
42+ $ products ->clear ();
43+ unset($ products , $ criteria );
44+ gc_collect_cycles ();
45+
46+ // --- DEBUG PAMIĘCI START ---
47+ // Przeliczamy bajty na megabajty dla czytelności
48+ $ memoryUsageMB = memory_get_usage (true ) / 1024 / 1024 ;
49+ $ peakMemoryMB = memory_get_peak_usage (true ) / 1024 / 1024 ;
50+
51+ echo sprintf (
52+ "[%s] Offset: %d | Memory: %.2f MB | Peak: %.2f MB \n" ,
53+ date ('H:i:s ' ),
54+ $ offset ,
55+ $ memoryUsageMB ,
56+ $ peakMemoryMB
57+ );
58+ // --- DEBUG PAMIĘCI END ---
59+
60+ $ offset += $ batchSize ;
3461 }
3562 }
3663
@@ -39,24 +66,30 @@ public function getProducedExportEntityType(): string
3966 return ExportProductEntity::class;
4067 }
4168
42- private function getCriteria (int $ batchSize ): Criteria
69+ private function getCriteria (int $ batchSize, int $ offset ): Criteria
4370 {
4471 $ criteria = new Criteria ();
4572 $ criteria ->setLimit ($ batchSize );
73+ $ criteria ->setOffset ($ offset );
4674 $ criteria ->addAssociation ('categories ' );
4775 $ criteria ->addAssociation ('categoriesRo ' );
48- $ criteria ->addAssociation ('children.options.group ' );
4976 $ criteria ->addAssociation ('manufacturer ' );
50- $ criteria ->addAssociation ('properties ' );
51- $ criteria ->addAssociation ('customFields ' );
5277 $ criteria ->addAssociation ('properties.group ' );
53- $ criteria ->addAssociation ('seoUrls ' );
78+ $ criteria ->addAssociation ('options.group ' );
5479 $ criteria ->addAssociation ('media ' );
55- $ criteria ->addAssociation ('children.cover.media ' );
80+ $ criteria ->addAssociation ('cover.media ' );
81+ $ criteria ->addAssociation ('seoUrls ' );
82+ $ criteria ->addAssociation ('customFields ' );
83+
84+ $ criteria ->addAssociation ('configuratorSettings.option.group ' );
85+
5686 foreach ($ this ->customAssociations as $ association ) {
5787 $ criteria ->addAssociation ($ association );
5888 }
59- $ criteria ->addFilter (new EqualsFilter ('parentId ' , null ));
89+
90+ // UWAGA: Usunęliśmy addFilter(new EqualsFilter('parentId', null));
91+ // Chcemy eksportować płasko wszystko: zarówno rodziców jak i warianty,
92+ // więc nie filtrujemy tutaj po parentId!
6093
6194 return $ criteria ;
6295 }
0 commit comments