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

Caching in inheritance accessor functions #510

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

Conversation

otto001
Copy link

@otto001 otto001 commented Feb 23, 2022

The accessor functions for inheritance relations are overwritten in PolymorphicModel. This also disables the caching usually provided by django, creating multiple redundant SQL queries in certain situations:

parent = Parent.object.get(id=1)
c1 = parent.child  # retrieves child from db
c2 = parent.child  # retrieves child from db again!

This contradicts the default django behavior and can cause unnecessary overhead.

This PR fixes that issue by using the caching mechanism of the underlying field.
The new unit test test_polymorphic__accessor_caching validates this new feature.

@otto001 otto001 changed the title Caching in ingeritance accessor functions Caching in inheritance accessor functions Feb 23, 2022
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