Optimize BOM import by only calculating supplier SPN keys once

This commit is contained in:
MayNiklas 2026-01-25 20:36:35 +01:00
parent e9bc1be60e
commit 4b0fc08c86

View file

@ -274,6 +274,13 @@ class BOMImporter
$entries_by_key = []; // Track entries by name+part combination $entries_by_key = []; // Track entries by name+part combination
$mapped_entries = []; // Collect all mapped entries for validation $mapped_entries = []; // Collect all mapped entries for validation
// Fetch suppliers once for efficiency
$suppliers = $this->entityManager->getRepository(\App\Entity\Parts\Supplier::class)->findAll();
$supplierSPNKeys = [];
foreach ($suppliers as $supplier) {
$supplierSPNKeys[] = $supplier->getName() . ' SPN';
}
foreach ($csv->getRecords() as $offset => $entry) { foreach ($csv->getRecords() as $offset => $entry) {
// Apply field mapping to translate column names // Apply field mapping to translate column names
$mapped_entry = $this->applyFieldMapping($entry, $field_mapping, $field_priorities); $mapped_entry = $this->applyFieldMapping($entry, $field_mapping, $field_priorities);
@ -402,10 +409,7 @@ class BOMImporter
} }
// Add supplier part numbers dynamically // Add supplier part numbers dynamically
$suppliers = $this->entityManager->getRepository(\App\Entity\Parts\Supplier::class)->findAll(); foreach ($supplierSPNKeys as $spnKey) {
foreach ($suppliers as $supplier) {
$supplierName = $supplier->getName();
$spnKey = $supplierName . ' SPN';
if (isset($mapped_entry[$spnKey]) && !empty($mapped_entry[$spnKey])) { if (isset($mapped_entry[$spnKey]) && !empty($mapped_entry[$spnKey])) {
$comment_parts[] = $spnKey . ': ' . $mapped_entry[$spnKey]; $comment_parts[] = $spnKey . ': ' . $mapped_entry[$spnKey];
} }