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

feat(core): Augment data instead of copying it #5487

Merged
merged 11 commits into from
Mar 16, 2023
Merged

feat(core): Augment data instead of copying it #5487

merged 11 commits into from
Mar 16, 2023

Conversation

janober
Copy link
Member

@janober janober commented Feb 15, 2023

Currently, Code & Function-Nodes copy a lot of data just to make sure that not by accident anything that should not change gets changed. This PR will enable the same but just in a cheaper way.

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Feb 15, 2023
@janober janober marked this pull request as ready for review March 6, 2023 16:59
@janober janober requested a review from netroy March 6, 2023 16:59
Copy link
Contributor

@flipswitchingmonkey flipswitchingmonkey left a comment

Choose a reason for hiding this comment

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

I think this approach works, but it feels like we are re-inventing a number of things that we could get out of the box by using prototype chaining instead. As an example:

interface SomeObject {
  [key:string]: any;
  title: string;
  version: string;
  data: number;
}

const parent: SomeObject = {
  title: "Parent",
  version: "1",
  data: 1,
}
Object.freeze(parent);

const child1: SomeObject = Object.create(parent);
child1.title = "Child1";
child1.version = "1.1";
parent.data = 5;  // does not change!

const child2: SomeObject = Object.create(parent);
child2.title = "Child2";
child2.version = "1.2";

Object.freeze(child1);
child1.title = "Changed"; // does not change!

const grandChild: SomeObject = Object.create(child1);
grandChild.title = "GrandChild";
grandChild.version = "1.1.1";

function print(o: SomeObject) {
  console.log(`${o.title} version: ${o.version} data: ${o.data} parent: ${o.__proto__.title}`);
}

print(parent); // 'Parent version: 1 data: 1 parent: undefined'
print(child1); // 'Child1 version: 1.1 data: 1 parent: Parent'
print(child2); // 'Child2 version: 1.2 data: 1 parent: Parent'
print(grandChild); // 'GrandChild version: 1.1.1 data: 1 parent: Child1'

Edit: I can see how this does not solve the recursive freezing and deleting of properties problem, so the Proxy solution is probably the right way 👍

packages/workflow/src/AugmentObject.ts Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

Great PR! Please pay attention to the following items before merging:

Files matching packages/**:

  • If fixing bug, added test to cover scenario.
  • If addressing forum or Github issue, added link to description.

Files matching packages/**/*.ts:

  • Added unit tests to cover new or updated functionality.

Make sure to check off this list before asking for review.

Copy link
Member

@netroy netroy left a comment

Choose a reason for hiding this comment

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

We might be able to replace reflect-metadata calls with prototype chaining for possibly better performance. but that can be done in another PR.

@codecov
Copy link

codecov bot commented Mar 16, 2023

Codecov Report

Patch coverage: 92.00% and project coverage change: +0.04 🎉

Comparison is base (541850f) 13.05% compared to head (c0fa7f5) 13.10%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5487      +/-   ##
==========================================
+ Coverage   13.05%   13.10%   +0.04%     
==========================================
  Files        2462     2463       +1     
  Lines      112686   112761      +75     
  Branches    17498    17518      +20     
==========================================
+ Hits        14715    14780      +65     
- Misses      97471    97478       +7     
- Partials      500      503       +3     
Impacted Files Coverage Δ
packages/workflow/src/AugmentObject.ts 91.89% <91.89%> (ø)
packages/workflow/src/WorkflowDataProxy.ts 47.82% <100.00%> (+0.12%) ⬆️

... and 3 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@netroy netroy merged commit 0876c38 into master Mar 16, 2023
@netroy netroy deleted the augment-data branch March 16, 2023 14:14
@n8n-assistant n8n-assistant bot added the Upcoming Release Will be part of the upcoming release label Mar 16, 2023
@janober janober added Upcoming Release Will be part of the upcoming release and removed Upcoming Release Will be part of the upcoming release labels Mar 16, 2023
@janober
Copy link
Member Author

janober commented Mar 26, 2023

Got released with n8n@0.221.2

@janober
Copy link
Member Author

janober commented Mar 26, 2023

Got released with n8n@0.221.2

sunilrr pushed a commit to fl-g6/qp-n8n that referenced this pull request Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released Upcoming Release Will be part of the upcoming release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants