Score:0

Improve performance migration

br flag

I have a custom migration like this

<?php

namespace Drupal\my_import\Plugin\migrate\source;

use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_source_csv\Plugin\migrate\source\CSV;

/**
 * Extend CSV source.
 *
 * @MigrateSource(
 *   id = "my_source_csv",
 *   source_module = "my_import"
 * )
 */
class MySourceCSV extends CSV {

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    parent::prepareRow($row);
    // Prepare data for $row; 

  }
}

In the prepare data for $row step. I have some business logic and it take along time although this logic return an array same with every rows. Images this step take about 2 seconds, and import very larger rows...

So I want to create a global variable when starting import. and using this variable each rows, and when finish import clear this variable.

How can I implement this idea? With me global variable is better than process data and store in DB (example drupal state, still query each rows).

id flag
Does an object property not work?
br flag
@cilefen sorry what do you mean? My problem is about fllow of migration. each rows of csv file will call method prepareRow, and run my login business every rows. while my business logic return an array same with every rows.
id flag
In object-oriented programming, object properties can store values. This is what I mean. It's ordinary to check `if empty($this->foo) { //do expensive calculation}; $this->foo = $result_of_calculation;`.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.