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

Reduce number of queries to database for model_delta function #256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marko90b
Copy link

When field is a relation get_field_value requires at least 2 additional queries to database. If str method of related object contains further relations, much more queries might be required. Accessing internal attribute (field.attname, usually f'{field.name}_id'), however, doesn't require any additional database queries. Only when model_delta determines the field really changed, string representation of the related objects are obtained by querying database. This can increase time needed to save lots of objects (>100) in the same view, when these objects have many relations, but not many (if any) of them changed.

When field is a relation `get_field_value` requires at least 2 additional queries to database. If __str__ method of related object contains further relations, much more queries might be required. Accessing internal attribute (`field.attname`, usually `f'{field.name}_id'`), however, doesn't require any additional database queries. Only when `model_delta` determines the field really changed, string representation of the related objects are obtained by querying database. This can increase time needed to save lots of objects (>100) in the same view, when these objects have many relations, but not many (if any) of them changed.
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.

1 participant