Skip to content

Commit 5748724

Browse files
committed
Fix CI and add documentation
1 parent 94355ca commit 5748724

5 files changed

Lines changed: 46 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Unreleased
33
### Add
44
- Add Recently viewed component
5+
- Add worker command for product export - reduce memory usage and increase performance for big catalogs
56

67
### Change
78
- Upgrade Web Components version to v5.2.1

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,15 @@ This is especially useful if you have several SalesChannels with different domai
364364

365365
APP_URL=http://saleschannel-domain.com php [SHOPWARE_ROOT]/bin/console factfinder:data:export
366366

367+
##### Running export with a worker
368+
369+
Since version 7.3.0, we've introduced a new export flow based on the worker.
370+
The biggest advantage of this export method is the reduced memory usage, which is especially helpful when you have a large or complex products catalog.
371+
Currently, this command is only available from the CLI and can be executed by:
372+
373+
php [SHOPWARE_ROOT]/bin/console factfinder:data:worker-export
374+
375+
The options are the same as described above for `factfinder:data:export`
367376

368377
#### Selecting Categories for CMS Export
369378
With CMS Export we introduced custom field for CategoryEntity by which we filter the Categories going to be exported.

src/Command/ExportBatchCommand.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
use Symfony\Component\Console\Input\InputInterface;
2222
use Symfony\Component\Console\Output\OutputInterface;
2323

24+
/**
25+
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
*/
2428
#[AsCommand(name: 'factfinder:export:batch', description: 'Internal worker command for exporting a batch of products', hidden: true)]
2529
class ExportBatchCommand extends Command
2630
{
@@ -66,13 +70,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6670
$input->getArgument('language')
6771
);
6872

69-
$entityClass = ProductEntity::class;
70-
$feedService = $this->feedFactory->create($context, $entityClass);
71-
72-
$fileResource = fopen($filePath, 'a');
73-
$out = new CsvFile($fileResource);
74-
75-
$feedColumns = $this->getFeedColumns('products', ProductEntity::class);
73+
$entityClass = ProductEntity::class;
74+
$feedService = $this->feedFactory->create($context, $entityClass);
75+
$fileResource = fopen($filePath, 'a');
76+
$out = new CsvFile($fileResource);
77+
$feedColumns = $this->getFeedColumns('products', ProductEntity::class);
7678
$processedCount = $feedService->generateBatch($out, $feedColumns, $offset, $limit, $offset === 0);
7779

7880
fclose($fileResource);
Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
* @SuppressWarnings(PHPMD.MissingImport)
4545
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4646
*/
47-
#[AsCommand(name: 'factfinder:product-data:export')]
48-
class ProductDataExportCommand extends Command
47+
#[AsCommand(name: 'factfinder:data:worker-export')]
48+
class WorkerDataExportCommand extends Command
4949
{
5050
public const SALES_CHANNEL_ARGUMENT = 'sales_channel';
5151
public const SALES_CHANNEL_LANGUAGE_ARGUMENT = 'language';
@@ -105,6 +105,9 @@ public function configure(): void
105105
/**
106106
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
107107
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
108+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
109+
* @SuppressWarnings(PHPMD.NPathComplexity)
110+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
108111
*/
109112
public function execute(InputInterface $input, OutputInterface $output): int
110113
{
@@ -191,18 +194,18 @@ public function execute(InputInterface $input, OutputInterface $output): int
191194
break;
192195
}
193196

194-
$workerMemory = $result['memory'] ?? 0;
195-
$workerPeak = $result['peak'] ?? 0;
196-
$masterPeak = memory_get_peak_usage(true) / 1024 / 1024;
197-
198-
$output->writeln(sprintf(
199-
'[%s] Offset: %d | Worker Peak: %.2f MB | Worker Final: %.2f MB | MASTER PEAK: %.2f MB',
200-
date('H:i:s'),
201-
$offset,
202-
$workerPeak,
203-
$workerMemory,
204-
$masterPeak
205-
));
197+
// Uncomment if you want to debug memory consumption for each batch
198+
// $workerMemory = $result['memory'] ?? 0;
199+
// $workerPeak = $result['peak'] ?? 0;
200+
// $masterPeak = memory_get_peak_usage(true) / 1024 / 1024;
201+
// $output->writeln(sprintf(
202+
// '[%s] Offset: %d | Worker: %.2f MB | Worker Final: %.2f MB | MASTER: %.2f MB',
203+
// date('H:i:s'),
204+
// $offset,
205+
// $workerPeak,
206+
// $workerMemory,
207+
// $masterPeak
208+
// ));
206209

207210
$offset += $batchSize;
208211
}
@@ -214,7 +217,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
214217
// Old flow for CMS, CATEGORY and BRANDS
215218
$feedService = $this->feedFactory->create($context, $entityClass);
216219
$out = $needFile ? new CsvFile($this->file) : new ConsoleOutput($output);
217-
218220
$feedService->generate($out, $feedColumns);
219221
}
220222

@@ -228,13 +230,13 @@ public function execute(InputInterface $input, OutputInterface $output): int
228230
$this->pushImportService->execute();
229231
}
230232

231-
// if (!$saveFile && $this->file) {
232-
// $metaData = stream_get_meta_data($this->file);
233-
//
234-
// if (file_exists($metaData['uri'])) {
235-
// unlink($metaData['uri']);
236-
// }
237-
// }
233+
if (!$saveFile && $this->file) {
234+
$metaData = stream_get_meta_data($this->file);
235+
236+
if (file_exists($metaData['uri'])) {
237+
unlink($metaData['uri']);
238+
}
239+
}
238240

239241
return Command::SUCCESS;
240242
}
@@ -293,7 +295,7 @@ private function getExportedEntityClass(string $exportType): string
293295
*/
294296
private function createFile(string $exportType, string $salesChannelId)
295297
{
296-
$dir = $this->kernelProjectDir . '/var/factfinder/newflow';
298+
$dir = $this->kernelProjectDir . '/var/factfinder';
297299

298300
if (!is_dir($dir)) {
299301
mkdir($dir);

src/Export/ExportProducts.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ public function getBatchByContext(SalesChannelContext $context, int $limit, int
4242
foreach ($products->getElements() as $product) {
4343
yield $product;
4444
}
45-
46-
// $products->clear();
47-
// unset($products, $criteria);
48-
// gc_collect_cycles();
4945
}
5046

5147
public function getProducedExportEntityType(): string
@@ -72,9 +68,11 @@ private function getCriteria(int $batchSize, ?int $offset = null): Criteria
7268
$criteria->addAssociation('seoUrls');
7369
$criteria->addAssociation('media');
7470
$criteria->addAssociation('children.cover.media');
71+
7572
foreach ($this->customAssociations as $association) {
7673
$criteria->addAssociation($association);
7774
}
75+
7876
$criteria->addFilter(new EqualsFilter('parentId', null));
7977

8078
return $criteria;

0 commit comments

Comments
 (0)