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

add 'node_type' to list of immutable model fields #3619

Merged
merged 1 commit into from
Dec 9, 2019

Conversation

ltalirz
Copy link
Member

@ltalirz ltalirz commented Dec 9, 2019

Fixes #1700

In the conversion from a backend entity to an ORM entity, the
node_type attribute of the ModelWrapper is requested, which triggered
a database query.
This meant that a QueryBuilder returning N nodes actually caused 1+N
queries to the database instead of 1 (with obvious performance hits).

By making 'node_type' explicitly immutable (changing the type of a node
should not be allowed), requesting it no longer triggers a database
query.

Note: Currently, the IMMUTABLE_MODEL_FIELDS is a global list, which is applied to all models.
As @muhrin mentioned, we might want to add an immutable_fields property to the models so that they can define their own immutable fields. Happy to open an issue for this.

In the conversion from a backend entity to an ORM entity, the
`node_type` attribute of the ModelWrapper is requested, which triggered
a database query.
This meant that a QueryBuilder returning N nodes actually caused 1+N
queries to the database instead of 1 (with obvious performance hits).

By making 'node_type' explicitly immutable (changing the type of a node
should not be allowed), requesting it no longer triggers a database
query.
Copy link
Contributor

@muhrin muhrin left a comment

Choose a reason for hiding this comment

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

Yes

@ltalirz ltalirz merged commit 6b91888 into aiidateam:develop Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[django] querybuilder projections very inefficient
2 participants