Skip to content

Commit

Permalink
Replace usage of in_array() within MigrateExecutable::handleMissingSo…
Browse files Browse the repository at this point in the history
…urceRows().

Adds a new method getSourceIdKey() to serialize the source ID data into a unique key for retrieval later.

Refer to drush-ops#5765
  • Loading branch information
mdolnik-eelzee committed Sep 25, 2023
1 parent 17c9277 commit e7823ae
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Drupal/Migrate/MigrateExecutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ public function onPreImport(MigrateImportEvent $event): void
$this->initProgressBar($migration);
}

/**
* The array key to use to represent Source ID values.
*
* Helps speed up array searched by serializing the value for a key.
*
* @param array $source_id
* The Source ID array.
*
* @return string
* The array key to represent Source ID values.
*/
protected function getSourceIdKey(array $source_id): string
{
return implode('-', $source_id);
}

/**
* Handles missing source rows after import.
*
Expand Down Expand Up @@ -242,7 +258,8 @@ protected function handleMissingSourceRows(MigrationInterface $migration): void
$destinationIds = [];
while ($idMap->valid()) {
$mapSourceId = $idMap->currentSource();
if (!in_array($mapSourceId, $this->allSourceIdValues)) {
$sourceIdKey = $this->getSourceIdKey($mapSourceId);
if (!isset($this->allSourceIdValues[$sourceIdKey])) {
$destinationIds[] = $idMap->currentDestination();
}
$idMap->next();
Expand Down Expand Up @@ -479,7 +496,8 @@ public function onPrepareRow(MigratePrepareRowEvent $event): void

// Collect all Source ID values so that we can handle missing source
// rows post import.
$this->allSourceIdValues[] = $sourceId;
$sourceIdKey = $this->getSourceIdKey($sourceId);
$this->allSourceIdValues[$sourceIdKey] = $sourceId;

if ($this->feedback && $this->counter && $this->counter % $this->feedback === 0) {
$this->importFeedbackMessage(false);
Expand Down

0 comments on commit e7823ae

Please sign in to comment.