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

[INVE-24636] Improve diffItems function performance #71

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
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
18 changes: 15 additions & 3 deletions packages/core/src/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1602,8 +1602,10 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
const self = this;
let item: INode;
const itemMap: NodeMap = this.get('itemMap');
const itemsArray = (items as { [key: string]: any[] })[`${type}s`];
const itemsToAdd: { type: ITEM_TYPE; model: NodeConfig | EdgeConfig }[] = [];

each(models, model => {
each(models, (model: NodeConfig | EdgeConfig) => {
item = itemMap[model.id];
if (item) {
if (self.get('animate') && type === NODE) {
Expand All @@ -1617,13 +1619,23 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs

self.updateItem(item, model, false);
} else {
item = self.addItem(type, model, false) as any;
itemsToAdd.push({ type, model });
}

if (item) {
(items as { [key: string]: any[] })[`${type}s`].push(item);
itemsArray.push(item);
}
});

if (itemsToAdd.length) {
const items = self.addItems(itemsToAdd, false);
for (var i = 0; i < items.length; i++) {
const item = items[i];
if (item) {
itemsArray.push(item);
}
}
}
}

/**
Expand Down