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

Import perf improvement #7604

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/plugins/importFromJSONAction/ImportFromJSONAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
* @returns {object}
*/
_generateNewIdentifiers(tree, namespace) {
this.oldToNewIdMap = {};

Check warning on line 154 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L154

Added line #L154 was not covered by tests
// For each domain object in the file, generate new ID, replace in tree
Object.keys(tree.openmct).forEach((domainObjectId) => {
const newId = {
Expand All @@ -160,10 +161,33 @@

const oldId = parseKeyString(domainObjectId);

tree = this._rewriteId(oldId, newId, tree);
let newIdKeyString = this.openmct.objects.makeKeyString(newId);
let oldIdKeyString = this.openmct.objects.makeKeyString(oldId);
this.oldToNewIdMap[oldIdKeyString] = newIdKeyString;

Check warning on line 166 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L164-L166

Added lines #L164 - L166 were not covered by tests
}, this);

return tree;
return JSON.parse(JSON.stringify(tree), (key, value) => {
if (value !== undefined && value !== null) {
if (

Check warning on line 171 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L169-L171

Added lines #L169 - L171 were not covered by tests
Object.prototype.hasOwnProperty.call(value, 'key') &&
Object.prototype.hasOwnProperty.call(value, 'namespace')
) {
const oldIdKeyString = this.openmct.objects.makeKeyString(value);
const newIdKeyString = this.oldToNewIdMap[oldIdKeyString];
const newId = this.openmct.objects.parseKeyString(newIdKeyString);

Check warning on line 177 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L175-L177

Added lines #L175 - L177 were not covered by tests

return newId;
} else if (typeof value === 'string') {
const possibleSubstitution = this.oldToNewIdMap[value];
if (possibleSubstitution !== undefined) {
const newId = this.openmct.objects.parseKeyString(possibleSubstitution);

Check warning on line 183 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L179-L183

Added lines #L179 - L183 were not covered by tests

return newId;

Check warning on line 185 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L185

Added line #L185 was not covered by tests
}
}
}
return value;

Check warning on line 189 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L189

Added line #L189 was not covered by tests
});
}
/**
* @private
Expand Down