Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-107: fix out of memory when fetching Top objects with lots of children #112

Merged
merged 24 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fb2ee43
Committing even if not ready yet
DiegoPino Jul 28, 2022
b3ab7ce
haha! No more memory issues
DiegoPino Jul 28, 2022
b7d589e
Give data nerds some hints of what is happening!
DiegoPino Jul 28, 2022
381b4b1
This upps the increments now that we now this won't fail on memory
DiegoPino Jul 28, 2022
c019e44
Disabled for now deep traverse
DiegoPino Jul 29, 2022
1f751ee
Fixes (for now just adds an empty) dataOriginal for AMI sets.
DiegoPino Aug 2, 2022
f2cbbbc
Much better increment
DiegoPino Aug 2, 2022
7fe8d1d
Validates Mapping to avoid Node to Node to end with UUID mappings
DiegoPino Aug 2, 2022
75e6c37
Fixes the problem with Child CMODEL Mappings v/s Top Object ones
DiegoPino Aug 2, 2022
4adc794
Not sure if this is correct
DiegoPino Aug 2, 2022
3baab4c
Update AmiMultiStepIngest.php
DiegoPino Aug 2, 2022
caca48f
Update src/Controller/AmiRowAutocompleteHandler.php
DiegoPino Aug 2, 2022
f145f27
Update src/Controller/AmiRowAutocompleteHandler.php
DiegoPino Aug 2, 2022
df2df8f
Update src/Form/AmiMultiStepIngest.php
DiegoPino Aug 2, 2022
f9c44f2
Update src/Form/AmiMultiStepIngest.php
DiegoPino Aug 2, 2022
94f377a
Update src/Plugin/ImporterAdapter/SolrImporter.php
DiegoPino Aug 2, 2022
2eff6a4
Update src/Plugin/ImporterAdapter/SolrImporter.php
DiegoPino Aug 2, 2022
1113e6e
Update src/Plugin/ImporterAdapter/SolrImporter.php
DiegoPino Aug 2, 2022
e09f675
Update src/Plugin/ImporterAdapter/SolrImporter.php
DiegoPino Aug 2, 2022
5b99a68
Update src/Plugin/ImporterAdapter/SolrImporter.php
DiegoPino Aug 2, 2022
2f7ca8b
Update src/Plugin/ImporterAdapter/SolrImporter.php
DiegoPino Aug 2, 2022
78f0cbe
Update src/Form/AmiMultiStepIngest.php
DiegoPino Aug 2, 2022
447ff43
Update src/Plugin/ImporterAdapter/SolrImporter.php
DiegoPino Aug 2, 2022
8a34799
Add manuscriptCModel as possible Top Object
DiegoPino Aug 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/AmiUtilityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,15 @@ public function csv_touch(string $filename = NULL) {
* 'data' will be rows and may/not be associative.
*
* @param string $uuid_key
* The header key can has/should have the UUIDs of new/existing ADOs.
* @param boolean $auto_uuid
* Defines if we are going to generate UUIDs when not valid/not present
* Or leave the $uuid_key field as it is and let this fail/if later.
*
* @return int|string|null
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function csv_save(array $data, $uuid_key = 'node_uuid') {
public function csv_save(array $data, $uuid_key = 'node_uuid', $auto_uuid = TRUE) {

//$temporary_directory = $this->fileSystem->getTempDirectory();
// We should be allowing downloads for this from temp
Expand Down Expand Up @@ -959,7 +963,7 @@ public function csv_save(array $data, $uuid_key = 'node_uuid') {
* @return int|string|null
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function csv_append(array $data, File $file, $uuid_key = 'node_uuid', bool $append_header = TRUE, $escape_characters = TRUE) {
public function csv_append(array $data, File $file, $uuid_key = 'node_uuid', bool $append_header = TRUE, $escape_characters = TRUE, $auto_uuid = TRUE) {

$wrapper = $this->streamWrapperManager->getViaUri($file->getFileUri());
if (!$wrapper) {
Expand Down
14 changes: 6 additions & 8 deletions src/Controller/AmiRowAutocompleteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function __construct(AccountInterface $current_user, AmiUtilityService $a
$this->currentUser = $current_user;
$this->entityTypeManager = $entity_type_manager;
$this->AmiUtilityService = $ami_utility;

}

/**
Expand Down Expand Up @@ -81,7 +80,6 @@ public function handleAutocomplete(Request $request, amiSetEntity $ami_set_entit
return new JsonResponse($results);
}


if (!$ami_set_entity) {
return new JsonResponse($results);
}
Expand Down Expand Up @@ -229,7 +227,6 @@ public static function ajaxPreviewAmiSet($form, FormStateInterface $form_state)
}
}


// Set initial context.
$context = [
'node' => NULL,
Expand Down Expand Up @@ -278,9 +275,10 @@ public static function ajaxPreviewAmiSet($form, FormStateInterface $form_state)
];
$output['json']['dataOriginal'] = [
'#type' => 'codemirror',
'#title' => t('Original JSON of this ADO <b>{{ dataOriginal.keyname.lod_endpoint_type }}</b> :'),
'#title' => t('Original JSON of an ADO <b>{{ dataOriginal.keyname }}</b> :'),
'#description' => t('This data structure will contain the original values (before modification) of an ADO only when updating. Sadly we can not at this time preview it during an AMI set preview.'),
'#rows' => 60,
'#value' => json_encode($context['dataOriginal'], JSON_PRETTY_PRINT),
'#value' => json_encode('{}', JSON_PRETTY_PRINT),
'#codemirror' => [
'lineNumbers' => FALSE,
'toolbar' => FALSE,
Expand Down Expand Up @@ -400,8 +398,8 @@ public static function ajaxPreviewAmiSet($form, FormStateInterface $form_state)
'#open' => TRUE,
'#title' => !$file ? t('AMI Set has no CSV File'): t('AMI Set has no data for chosen row.'),
'error' => [
'#markup' => $message,
]
'#markup' => t('The AMI set is empty.'),
],
];
$response->addCommand(new OpenOffCanvasDialogCommand(t('Preview'),
$output, ['width' => '50%']));
Expand Down Expand Up @@ -437,4 +435,4 @@ public static function rowAjaxCallback($form, FormStateInterface $form_state) {
return $response;
}

}
}
88 changes: 70 additions & 18 deletions src/Form/AmiMultiStepIngest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// TO keep this discrete and easier to edit maybe move to it's own method?
if ($this->step == 3) {
// We should never reach this point if data is not enough. Submit handler
// will back to Step 2 if so.
$data = $this->store->get('data');
// will go back to Step 2 if so.
$data = $this->store->get('data') ?? [];
$pluginconfig = $this->store->get('pluginconfig');
$plugin_instance = $this->store->get('plugininstance');
$op = $pluginconfig['op'];
Expand Down Expand Up @@ -150,12 +150,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#description' => $this->t('Columns will be casted to ADO metadata (JSON) using a Twig template setup for JSON output'),
];

/* $element_conditional['webform'] =[
'#type' => 'select',
'#title' => $this->t('Webform'),
'#options' => $webform,
'#description' => $this->t('Columns are casted to ADO metadata (JSON) by passing/validating Data through an existing Webform'),
];*/
/**
* $element_conditional['webform'] = [
* '#type' => 'select',
* '#title' => $this->t('Webform'),
* '#options' => $webform,
* '#description' => $this->t('Columns are casted to ADO metadata (JSON) by passing/validating Data through an existing Webform'),
* ];
*/

$form['ingestsetup']['globalmapping'] = [
'#type' => 'select',
Expand Down Expand Up @@ -291,7 +293,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
}

if ($this->step == 4) {
$data = $this->store->get('data');
$data = $this->store->get('data') ?? [];
$pluginconfig = $this->store->get('pluginconfig');
$op = $pluginconfig['op'];
$plugin_instance = $this->store->get('plugininstance');
Expand Down Expand Up @@ -327,7 +329,12 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#required' => FALSE,
'#description' => $node_description,
'#empty_option' => $this->t('- Please select columns -'),
'#element_validate' => ['::validateMapping'],
];

// Enforce this checked for ANY plugin that implements/defines its process
// as batch. I can not see any reason why a remote service would provide UUIDs.
// @TODO ask Allison/Katie about edge cases?
if ($op == 'update' || $op == 'patch') {
$form['ingestsetup']['adomapping']['autouuid'] = [
'#type' => 'checkbox',
Expand All @@ -341,14 +348,17 @@ public function buildForm(array $form, FormStateInterface $form_state) {
];
}
else {
$autouuid = $plugin_instance->getPluginDefinition()['batch'] ?? FALSE;
$autouuid = $autouuid == TRUE ? $autouuid: (isset($adomapping['autouuid']) ? $adomapping['autouuid'] : TRUE);
$form['ingestsetup']['adomapping']['autouuid'] = [
'#type' => 'checkbox',
'#title' => $this->t('Automatically assign UUID'),
'#description' => $this->t(
'Check this to automatically Assign UUIDs to each ADO. <br/><b>Important</b>: AMI will generate those under a <b>node_uuid</b> column.<br/>If you data already contains a <b>node_uuid</b> column with UUIDs inside, existing values will be used.'
),
'#required' => FALSE,
'#default_value' => isset($adomapping['autouuid']) ? $adomapping['autouuid'] : TRUE,
'#disabled' => $plugin_instance->getPluginDefinition()['batch'] ?? FALSE,
'#default_value' => $autouuid,
];
}
$form['ingestsetup']['adomapping']['uuid'] = [
Expand All @@ -359,8 +369,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
),
'#description_display' => 'before',
'#empty_option' => $this->t('- Let AMI decide -'),
'#empty_value' => NULL,
'#default_value' => isset($adomapping['uuid']) ? $adomapping['uuid'] : [],
'#empty_value' => 'node_uuid',
'#default_value' => $plugin_instance->getPluginDefinition()['batch'] ? 'node_uuid' : (isset($adomapping['uuid']) ? $adomapping['uuid'] : []),
'#required' => FALSE,
'#source' => [ 'uuid' => 'ADO UUID'],
'#source__title' => $this->t('ADO mappings'),
Expand All @@ -373,14 +383,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'required' => [
':input[name*="autouuid"]' => ['checked' => FALSE],
]
]
],
];
if ($op == 'update' || $op == 'patch') {
unset($form['ingestsetup']['adomapping']['uuid']['#states']);
$form['ingestsetup']['adomapping']['uuid']['#required'] = TRUE;
}

$form['ingestsetup']['adomapping']['base'] = [
$form['ingestsetup']['adomapping']['base'] = [
'#type' => 'webform_mapping',
'#title' => $this->t('Required ADO mappings'),
'#format' => 'list',
Expand Down Expand Up @@ -422,6 +432,41 @@ public function buildForm(array $form, FormStateInterface $form_state) {
return $form;
}

/**
* Validate handler for the "mapping" fase.
*
* Checks for double mapped elements.
*/
public function validateMapping(array &$form, FormStateInterface $form_state) {
if ($form_state->getTriggeringElement()['#name'] == 'next') {
$uuid_map = $form_state->getValue(
['adomapping', 'uuid', 'uuid'], 'node_uuid'
);
if ($uuid_map == "") {
$uuid_map = 'node_uuid';
}
$parents_map = $form_state->getValue(
['adomapping', 'parents'], []
);
if (in_array($uuid_map, $parents_map)) {
if (!$form_state->getValue(
['adomapping', 'autouuid'], FALSE)
) {
$form_state->setErrorByName(
'adomapping][parents',
$this->t('UUID and Parents can not share Column names.'));
}
else {
$form_state->setErrorByName(
'adomapping][parents',
$this->t('When Auto UUID is enabled, <em>"node_uuid"</em> can not be set as parent.'));

}
}
}
}


/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -533,13 +578,20 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$amisetdata->total_rows = $data['totalrows'];
}

// We should probably add the UUIDs here right now.
$uuid_key = isset($amisetdata->adomapping['uuid']['uuid']) && !empty($amisetdata->adomapping['uuid']['uuid']) ? $amisetdata->adomapping['uuid']['uuid'] : 'node_uuid';
/* remove from the mappings any column used as file source */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave this one as it is. Single commends can have /* */ or even //

if (isset($amisetdata->adomapping['autouuid']) && $amisetdata->adomapping['autouuid']) {
$uuid_key = 'node_uuid';
}
else {
$uuid_key = isset($amisetdata->adomapping['uuid']['uuid']) && !empty($amisetdata->adomapping['uuid']['uuid']) ? $amisetdata->adomapping['uuid']['uuid'] : 'node_uuid';
}
// We want to reset this value now
$amisetdata->adomapping['uuid']['uuid'] = $uuid_key;
if (!$plugin_instance->getPluginDefinition()['batch']) {
$fileid = $this->AmiUtilityService->csv_save($data, $uuid_key);
} else {
// We now pass also if auto UUID was chosen or not.
$fileid = $this->AmiUtilityService->csv_save($data, $uuid_key, $amisetdata->adomapping['autouuid'] ?? FALSE);
}
else {
$fileid = $this->AmiUtilityService->csv_touch();
}
$batch = [];
Expand Down
Loading